This commit is contained in:
blank
2021-06-07 15:13:32 +08:00
parent 74d5947e9d
commit 346fc42e67
500 changed files with 77303 additions and 1 deletions

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cx3.blank.demo"
android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
<meta-data android:name="android.app.lib_name"
android:value="cocos" />
<!-- 高德定位 -->
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="418378a88b3e94a77fa3548b5b43afc0" />
<service android:name="com.amap.api.location.APSService"></service>
<activity
android:name=".AppActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:launchMode="singleTask"
android:taskAffinity="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.cocos.lib.CocosEditBoxActivity"
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
android:screenOrientation="behind"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
</application>
</manifest>

View File

@@ -0,0 +1,69 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
buildToolsVersion PROP_BUILD_TOOLS_VERSION
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "cx3.blank.demo"
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
}
packagingOptions {
exclude 'META-INF/LICENSE'
}
sourceSets.main {
manifest.srcFile "AndroidManifest.xml"
java.srcDirs "src"
res.srcDirs "res"
jniLibs.srcDirs = ["libs", "../../../../cx-framework3.1/cocos3-libs/cocos3-libso/build/app/intermediates/cmake/release/obj"]
assets.srcDirs = ['../../assets', '../../boot', '../../statics']
}
signingConfigs {
release {
if (project.hasProperty("RELEASE_STORE_FILE")) {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
debuggable false
jniDebuggable false
renderscriptDebuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
}
debug {
debuggable true
jniDebuggable true
renderscriptDebuggable true
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation project(':libcc')
implementation 'com.amap.api:location:latest.integration'
// implementation 'com.android.support:appcompat-v7:28.0.0'
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

View File

@@ -0,0 +1,50 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in E:\developSoftware\Android\SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Proguard Cocos2d-x-lite for release
-keep public class com.cocos.** { *; }
-dontwarn com.cocos.**
# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
# Proguard okhttp for release
-keep class okhttp3.** { *; }
-dontwarn okhttp3.**
-keep class okio.** { *; }
-dontwarn okio.**
# Proguard Android Webivew for release. you can comment if you are not using a webview
-keep public class android.net.http.SslError
-keep public class android.webkit.WebViewClient
-dontwarn android.webkit.WebView
-dontwarn android.net.http.SslError
-dontwarn android.webkit.WebViewClient
# keep anysdk for release. you can comment if you are not using anysdk
-keep public class com.anysdk.** { *; }
-dontwarn com.anysdk.**
# amapLocation
-keep class com.amap.api.location.**{*;}
-keep class com.amap.api.fence.**{*;}
-keep class com.loc.**{*;}
-keep class com.autonavi.aps.amapapi.model.**{*;}

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#60A7C6FC">
<FrameLayout
android:id="@+id/contentView"
android:layout_width="157dp"
android:layout_height="561dp" android:background="#ff0000FC" android:clipChildren="false" android:clipToPadding="false">
<FrameLayout
android:id="@+id/contentView1"
android:layout_width="355dp"
android:layout_height="517dp" android:background="#FC5800">
<view android:layout_width="285dp" android:layout_height="354dp">
<view android:layout_width="222dp" android:layout_height="222dp">
</view>
</view>
<EditText
android:id="@+id/editText"
android:layout_width="283dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="dddddddddddddddddddddddddddddddddddddaa"/>
</FrameLayout>
</FrameLayout>
</FrameLayout>

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="vertical" >
<!--android:background="@color/mediacontroller_bg"-->
<!--<LinearLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:visibility="visible"-->
<!--android:orientation="horizontal" >-->
<!--<TextView-->
<!--android:id="@+id/mediacontroller_time_current"-->
<!--style="@style/MediaController_Text"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginLeft="30dp"-->
<!--android:layout_weight="1"-->
<!--android:text="00:00" />-->
<!--<TextView-->
<!--android:id="@+id/mediacontroller_time_total"-->
<!--style="@style/MediaController_Text"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginRight="30dp"-->
<!--android:layout_weight="1"-->
<!--android:gravity="right"-->
<!--android:text="22:33" />-->
<!--</LinearLayout>-->
<!--<RelativeLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:orientation="horizontal" >-->
<!--<ImageButton-->
<!--android:id="@+id/mediacontroller_play_pause"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_centerVertical="true"-->
<!--android:layout_marginLeft="5dp"-->
<!--android:background="@drawable/mediacontroller_button"-->
<!--android:contentDescription="@string/mediacontroller_play_pause"-->
<!--android:src="@drawable/mediacontroller_pause" />-->
<!--<ImageButton-->
<!--android:id="@+id/mediacontroller_play_fs"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_alignParentRight="true"-->
<!--android:layout_centerVertical="true"-->
<!--android:background="@drawable/mediacontroller_change_size"-->
<!--android:visibility="visible" />-->
<!--<org.cocos2dx.lib.MySeekBar-->
<!--android:id="@+id/mediacontroller_seekbar"-->
<!--style="@style/MediaController_SeekBar"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_centerVertical="true"-->
<!--android:layout_toLeftOf="@id/mediacontroller_play_fs"-->
<!--android:layout_toRightOf="@id/mediacontroller_play_pause"-->
<!--android:focusable="true"-->
<!--android:max="1000" />-->
<!--</RelativeLayout>-->
<!--<TextView-->
<!--android:id="@+id/mediacontroller_file_name"-->
<!--style="@style/MediaController_Text"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginLeft="5dp"-->
<!--android:ellipsize="marquee"-->
<!--android:singleLine="true" />-->
</LinearLayout>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name" translatable="false">cx-demo</string>
</resources>

View File

@@ -0,0 +1,49 @@
package cx3.blank.demo;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.cocos.lib.CocosActivity;
import cx3.blank.sdk.JsIntf;
public class AppActivity extends CocosActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (!isTaskRoot())
{
return;
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
mFrameLayout.setFitsSystemWindows(false);
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);
}
app = this;
JsIntf.init();
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] paramArrayOfInt)
{
PermsissionClass.onRequestPermissionsResult(requestCode, permissions, paramArrayOfInt);
}
}

View File

@@ -0,0 +1,106 @@
package cx3.blank.demo;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PermsissionClass
{
private static int mapMngRequestCode = 100;
private static Map<Integer, PermsissionReq> mapReq = new HashMap<>();
public interface PermsissionInterface
{
void checkPermissionCallback(int requestCode, boolean granted);
}
public static int makeRequestCode()
{
return ++mapMngRequestCode;
}
///////检查是否有权限并申请
public static void checkPermission(Context context, PermsissionInterface intf, int requestCode, String[] permissions)
{
PermsissionReq req = mapReq.get(requestCode);
if (req != null)
{
intf.checkPermissionCallback(requestCode, req.granted);
return;
}
if (Build.VERSION.SDK_INT < 23)
{
intf.checkPermissionCallback(requestCode, true);
return;
}
try
{
List<String> needRequestPermissonList = new ArrayList<>();
for (String perm : permissions)
{
if (context.getApplicationInfo().targetSdkVersion >= 23)
{
Method checkSelfMethod = context.getClass().getMethod("checkSelfPermission", String.class);
Method shouldShowRequestPermissionRationaleMethod = context.getClass().getMethod("shouldShowRequestPermissionRationale", String.class);
if ((Integer) checkSelfMethod.invoke(context, perm) != PackageManager.PERMISSION_GRANTED || (Boolean) shouldShowRequestPermissionRationaleMethod.invoke(context, perm))
needRequestPermissonList.add(perm);
}
// else
// {
// if (PermissionChecker.checkSelfPermission(context, perm) != PackageManager.PERMISSION_GRANTED)
// needRequestPermissonList.add(perm);
// }
}
if (needRequestPermissonList.size() == 0)
{
intf.checkPermissionCallback(requestCode, true);
return;
}
req = new PermsissionReq();
req.intf = intf;
req.granted = false;
mapReq.put(requestCode, req);
String[] array = needRequestPermissonList.toArray(new String[needRequestPermissonList.size()]);
Method method = context.getClass().getMethod("requestPermissions", new Class[]{String[].class, int.class});
method.invoke(context, array, requestCode);
} catch (Throwable e)
{
}
}
public static void onRequestPermissionsResult(int requestCode, String[] permissions, int[] paramArrayOfInt)
{
boolean granted = true;
for (int result : paramArrayOfInt)
{
if (result != PackageManager.PERMISSION_GRANTED)
{
granted = false;
break;
}
}
PermsissionReq req = mapReq.get(requestCode);
if (req != null)
{
req.granted = granted;
req.intf.checkPermissionCallback(requestCode, granted);
}
}
}
class PermsissionReq
{
public PermsissionClass.PermsissionInterface intf;
public boolean granted;
}

View File

@@ -0,0 +1,26 @@
package cx3.blank.sdk;
import cx.NativeIntf;
import cx.NativeParams;
import cx3.blank.sdk.system.SystemIntf;
import cx3.blank.sdk.video.VideoIntf;
public class JsIntf
{
public static void init()
{
NativeIntf.setJsIntf(JsIntf::call);
}
public static String call(NativeParams params)
{
String classname = params.classname;
if (classname.equals("system"))
return SystemIntf.ins().call(params);
if (classname.equals("video"))
return VideoIntf.ins().call(params);
return "";
}
}

View File

@@ -0,0 +1,63 @@
package cx3.blank.sdk.system;
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import com.cocos.lib.CocosActivity;
import cx.NativeParams;
import cx3.blank.demo.PermsissionClass;
public class SystemIntf
{
private static SystemIntf s_sharedSystemIntf = null;
public static SystemIntf ins()
{
if (s_sharedSystemIntf == null)
s_sharedSystemIntf = new SystemIntf();
return s_sharedSystemIntf;
}
public String call(NativeParams params)
{
String fname = params.fname;
if (fname.equals("callPhone"))
checkPermission(fname, params);
return "";
}
private final int permissionRequestCode = PermsissionClass.makeRequestCode();
private final String[] permissions = {
Manifest.permission.CALL_PHONE
};
private void checkPermission(String fname, NativeParams params)
{
PermsissionClass.checkPermission(CocosActivity.app, new PermsissionClass.PermsissionInterface()
{
@Override
public void checkPermissionCallback(int requestCode, boolean granted)
{
if (granted)
{
if (fname.equals("callPhone"))
callPhone(params.at(0).asString());
}
}
}, permissionRequestCode, permissions);
}
private void callPhone(String phone)
{
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
try
{
CocosActivity.app.startActivity(intent);
}
catch (SecurityException e)
{
}
}
}

View File

@@ -0,0 +1,184 @@
package cx3.blank.sdk.video;
import android.view.View;
import android.widget.FrameLayout;
import com.cocos.lib.CocosActivity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import cx.NativeParams;
import cx.mask.MaskIntf;
public class VideoIntf
{
private static VideoIntf s_sharedVideoIntf = null;
public static VideoIntf ins()
{
if (s_sharedVideoIntf == null)
s_sharedVideoIntf = new VideoIntf();
return s_sharedVideoIntf;
}
private Map<String, VideoView> videoMap = new HashMap();
private Map<String, ArrayList<NativeParams>> taskMap = new HashMap();
//创建video是在UI线程线程未完成时立即调用其他方法就取不到video因此用队列处理请求每一个video一个任务队列
public String call(NativeParams params)
{
String videoName = params.at(0).asString();
ArrayList<NativeParams> taskList = taskMap.get(videoName);
if (taskList == null)
{
taskList = new ArrayList();
taskMap.put(videoName, taskList);
}
taskList.add(params);
executeTask(taskList);
return "";
}
private void executeTask(ArrayList<NativeParams> taskList)
{
if (taskList.size() == 0)
return;
CocosActivity.app.runOnUiThread(new Runnable()
{
@Override
public void run()
{
while (taskList.size() > 0)
{
NativeParams params = taskList.remove(0);
callInternal(params);
}
}
});
}
public String callInternal(NativeParams params)
{
String fname = params.fname;
//删除指定maskView中的所有videoView
if (fname.equals("removeInMask"))
{
String maskName = params.at(0).asString();
removeInMask(maskName);
return "";
}
String videoName = params.at(0).asString();
if (fname.equals("createInMask"))
{
String maskName = params.at(1).asString();
float rectX = params.at(2).asFloat();
float rectY = params.at(3).asFloat();
float rectW = params.at(4).asFloat();
float rectH = params.at(5).asFloat();
createInMask(videoName, maskName, rectX, rectY, rectW, rectH);
return "";
}
else if (fname.equals("create"))
{
float rectX = params.at(1).asFloat();
float rectY = params.at(2).asFloat();
float rectW = params.at(3).asFloat();
float rectH = params.at(4).asFloat();
create(videoName, rectX, rectY, rectW, rectH);
return "";
}
VideoView videoView = videoMap.get(videoName);
if (videoView == null)
return "";
if (fname.equals("play"))
videoView.play(params.at(1).asString());
else if (fname.equals("setRoundRadius"))
videoView.setRoundRadius(params.at(1).asInt());
else if (fname.equals("setPosition"))
videoView.setPosition(Math.round(params.at(1).asFloat()), Math.round(params.at(2).asFloat()));
else if (fname.equals("setFullScreen"))
videoView.setFullScreen(params.at(1).asBool());
else if (fname.equals("pause"))
{
videoView.pausePlay();
if (params.at(1).asBool())
videoView.setVisibility(View.INVISIBLE);
}
else if (fname.equals("resume"))
{
videoView.startPlay();
if (videoView.getVisibility() == View.INVISIBLE)
videoView.setVisibility(View.VISIBLE);
}
else if (fname.equals("seekToTime"))
videoView.seekTo(params.at(1).asInt()); //seconds
else if (fname.equals("lockSeek"))
videoView.lockSeek(params.at(1).asBool());
else if (fname.equals("showBar"))
videoView.showBar(params.at(1).asBool());
else if (fname.equals("removeVideo"))
{
videoMap.remove(videoName);
taskMap.remove(videoName);
videoView.close();
}
return "";
}
public void createInMask(String videoName, String maskName, final float rectX, final float rectY, final float rectW, final float rectH)
{
if (videoMap.get(videoName) != null)
return;
FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lParams.leftMargin = Math.round(rectX);
lParams.topMargin = Math.round(rectY);
lParams.width = Math.round(rectW);
lParams.height = Math.round(rectH);
VideoView videoView = new VideoView(lParams);
if (maskName != null)
MaskIntf.ins().addNativeView(maskName, videoView, videoName, lParams);
else
CocosActivity.app.getFrameLayout().addView(videoView, 0, lParams);
videoMap.put(videoName, videoView);
}
public void create(String videoName, float rectX, float rectY, float rectW, float rectH)
{
createInMask(videoName, null, rectX, rectY, rectW, rectH);
}
public void removeInMask(final String maskName)
{
for (Iterator<Entry<String, VideoView>> it = videoMap.entrySet().iterator(); it.hasNext(); )
{
Entry<String, VideoView> item = it.next();
String videoName = item.getKey();
VideoView videoView = item.getValue();
it.remove();
taskMap.remove(videoName);
videoView.close();
}
}
}

View File

@@ -0,0 +1,383 @@
package cx3.blank.sdk.video;
import android.app.Activity;
import android.app.Service;
import android.content.pm.ActivityInfo;
import android.content.res.AssetFileDescriptor;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.opengl.GLSurfaceView;
import android.view.SurfaceHolder;
import android.widget.FrameLayout;
import android.widget.MediaController;
import com.cocos.lib.CocosActivity;
import cx.sys.SysIntf;
public class VideoView extends GLSurfaceView implements SurfaceHolder.Callback,
MediaController.MediaPlayerControl,
MediaPlayer.OnPreparedListener,
MediaPlayer.OnErrorListener
{
public static final int CB_COMPLETED = 1;
public static final int CB_ERROR = 2;
private Rect layoutRect = new Rect();
private String url = null;
private boolean isFullScreen = false;
private boolean isMute = false;
private boolean paused = false;
private boolean lockSeek = false;
private int roundRadius = 0;
private Activity activity;
private MediaPlayer mediaPlayer;
private MediaController controller;
private VideoViewInterface videoViewInterface = null;
private int mCurrentBufferPercentage = 0;
private static final String assetRoot = "@assets/";
public VideoView(FrameLayout.LayoutParams lParams)
{
super(CocosActivity.app, null);
this.activity = CocosActivity.app;
layoutRect.left = lParams.leftMargin;
layoutRect.top = lParams.topMargin;
layoutRect.right = lParams.width;
layoutRect.bottom = lParams.height;
getHolder().addCallback(this);
setKeepScreenOn(true);
setFocusable(true);
setFocusableInTouchMode(true);
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setOnBufferingUpdateListener(bufferingUpdateListener);
mediaPlayer.setOnCompletionListener(completionListener);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setScreenOnWhilePlaying(true);
//todo: controller ui
controller = new MediaController(CocosActivity.app);
controller.setAnchorView((FrameLayout)this.getParent());
//todo: video mask
// setWillNotDraw(false);
}
// @Override
// public void draw(Canvas canvas)
// {
// canvas.clipRect(new RectF(50, 50, 100, 100));
// super.draw(canvas);
// }
public void setPlayCallback(VideoViewInterface videoViewInterface)
{
this.videoViewInterface = videoViewInterface;
}
public interface VideoViewInterface
{
void callback(int flag, String value);
}
public void play(String url)
{
try
{
if (this.url != null)
{
mediaPlayer.pause();
mediaPlayer.reset();
}
this.url = url;
if (url.startsWith(assetRoot))
{
AssetFileDescriptor assetFileDescriptor = activity.getAssets().openFd(url.substring(assetRoot.length()));
mediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
}
/*
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && url.charAt(0) == '/')
{
Uri uri = FileProvider.getUriForFile(activity, activity.getPackageName() + ".fileProvider", new File(url));
mediaPlayer.setDataSource(activity, uri);
}
*/
else if (url.startsWith("http"))
mediaPlayer.setDataSource(activity, Uri.parse(url));
else
{
AssetFileDescriptor assetFileDescriptor = activity.getAssets().openFd(url);
mediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
}
mediaPlayer.prepareAsync();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void close()
{
if (mediaPlayer != null)
{
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
}
FrameLayout parent = (FrameLayout)getParent();
parent.removeView(this);
}
public void setFullScreen(boolean fullScreen)
{
if (isFullScreen == fullScreen)
return;
isFullScreen = fullScreen;
updateLayout();
}
public void updateLayout()
{
if (isFullScreen)
{
Point screenSize = SysIntf.getScreenSize();
FrameLayout.LayoutParams lParams = (FrameLayout.LayoutParams) this.getLayoutParams();
lParams.leftMargin = 0;
lParams.topMargin = 0;
lParams.width = screenSize.y;
lParams.height = screenSize.x;
this.setLayoutParams(lParams);
// CocosActivity.app.getFrameLayout().addView(this, lParams);
// CocosActivity.app.setRequestedOrientation(params.fullScreen ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
CocosActivity.app.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
else
{
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.getLayoutParams();
layoutParams.leftMargin = this.layoutRect.left;
layoutParams.topMargin = this.layoutRect.top;
layoutParams.width = this.layoutRect.right;
layoutParams.height = this.layoutRect.bottom;
this.setLayoutParams(layoutParams);
}
}
public void setPosition(int x, int y)
{
layoutRect.left = x;
layoutRect.top = y;
if (!isFullScreen)
{
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.getLayoutParams();
layoutParams.leftMargin = x;
layoutParams.topMargin = y;
this.setLayoutParams(layoutParams);
}
}
public void setRoundRadius(int radius)
{
this.roundRadius = radius;
}
public void seekToTime(int seconds)
{
}
public void lockSeek(boolean value)
{
this.lockSeek = value;
}
public void showBar(boolean value)
{
// playerBar = new MediaPlayerBar(this);
}
public void setMute(boolean mute)
{
if (this.isMute == mute)
return;
this.isMute = mute;
if (mediaPlayer == null)
return;
if (mute)
mediaPlayer.setVolume(0, 0);
else
{
AudioManager audioManager = (AudioManager)activity.getSystemService(Service.AUDIO_SERVICE);
int current = audioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
mediaPlayer.setVolume(current, current);
}
}
public void startPlay()
{
this.paused = false;
if (mediaPlayer != null)
mediaPlayer.start();
}
public void pausePlay()
{
this.paused = true;
if (mediaPlayer != null)
mediaPlayer.pause();
}
@Override
public void start()
{
if (mediaPlayer != null)
mediaPlayer.start();
}
public void stop()
{
if (mediaPlayer != null)
mediaPlayer.stop();
}
@Override
public void pause()
{
if (mediaPlayer != null)
mediaPlayer.pause();
}
@Override
public int getDuration()
{
return mediaPlayer != null ? mediaPlayer.getDuration() : 0;
}
@Override
public int getCurrentPosition()
{
return mediaPlayer != null ? mediaPlayer.getCurrentPosition() : 0;
}
@Override
public void seekTo(int pos)
{
if (mediaPlayer != null)
mediaPlayer.seekTo(pos);
}
@Override
public boolean isPlaying()
{
return mediaPlayer != null && mediaPlayer.isPlaying();
}
@Override
public int getBufferPercentage()
{
return mCurrentBufferPercentage;
}
@Override
public boolean canPause()
{
return true;
}
@Override
public boolean canSeekBackward()
{
return !lockSeek;
}
@Override
public boolean canSeekForward()
{
return !lockSeek;
}
@Override
public int getAudioSessionId()
{
return mediaPlayer.getAudioSessionId();
}
@Override
public void onPrepared(MediaPlayer mediaPlayer)
{
if (mediaPlayer != null)
{
this.updateLayout();
mediaPlayer.start();
}
}
@Override
public boolean onError(MediaPlayer mediaPlayer, int what, int extra)
{
if (videoViewInterface != null)
videoViewInterface.callback(CB_ERROR, null);
return false;
}
private MediaPlayer.OnBufferingUpdateListener bufferingUpdateListener = new MediaPlayer.OnBufferingUpdateListener()
{
public void onBufferingUpdate(MediaPlayer mp, int percent)
{
mCurrentBufferPercentage = percent;
}
};
private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener()
{
public void onCompletion(MediaPlayer mp)
{
if (videoViewInterface != null)
videoViewInterface.callback(CB_COMPLETED, null);
}
};
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
{
if (mediaPlayer != null)
mediaPlayer.setDisplay(holder);
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
//返回至前台时继续播放
if (mediaPlayer != null)
{
mediaPlayer.setDisplay(holder);
if (!paused)
mediaPlayer.start();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
if (mediaPlayer == null)
return;
//切换至后台时暂停
if (mediaPlayer.isPlaying())
mediaPlayer.pause();
}
}