1.修改集成SDK代码
Showing
11 changed files
with
299 additions
and
245 deletions
| ... | @@ -1439,6 +1439,10 @@ cc.Class({ | ... | @@ -1439,6 +1439,10 @@ cc.Class({ |
| 1439 | 1439 | ||
| 1440 | doCurrentFocusTVLinkAction: function (strAction) { | 1440 | doCurrentFocusTVLinkAction: function (strAction) { |
| 1441 | let strTVLink = this._fiCurrentFocus.getTVLink(); | 1441 | let strTVLink = this._fiCurrentFocus.getTVLink(); |
| 1442 | //福建测试视频播放功能 | ||
| 1443 | if (strTVLink == "{\"click\":[{\"action\":\"ChangeScene\",\"parameters\":{\"sceneName\":\"sceneGameCategory\",\"currentIndex\":\"0\"}}]}") { | ||
| 1444 | strTVLink = "{\"click\":[{\"action\":\"ChangeScene\",\"parameters\":{\"sceneName\":\"sceneVideoDetail\"}}]}"; | ||
| 1445 | } | ||
| 1442 | cc.log("tvlink===============" + strTVLink); | 1446 | cc.log("tvlink===============" + strTVLink); |
| 1443 | // cc.log("tvlink===============" + this._oSceneContext._iPageIndex); | 1447 | // cc.log("tvlink===============" + this._oSceneContext._iPageIndex); |
| 1444 | try { | 1448 | try { | ... | ... |
| ... | @@ -64,16 +64,16 @@ | ... | @@ -64,16 +64,16 @@ |
| 64 | <!-- 未来NewTV --> | 64 | <!-- 未来NewTV --> |
| 65 | <meta-data | 65 | <meta-data |
| 66 | android:name="NewTV.APPID" | 66 | android:name="NewTV.APPID" |
| 67 | android:value="0e0777adb659479" /> | 67 | android:value="8e663b3ce392485" /> |
| 68 | <meta-data | 68 | <meta-data |
| 69 | android:name="NewTV.channelCode" | 69 | android:name="NewTV.channelCode" |
| 70 | android:value="\2626035001" /> | 70 | android:value="\2626035001" /> |
| 71 | <meta-data | 71 | <meta-data |
| 72 | android:name="NewTV.Appkey" | 72 | android:name="NewTV.Appkey" |
| 73 | android:value="df4fc19c4673bf9b5e70a7a56ece35e5" /> | 73 | android:value="4b9ee656631d5d78f112c7ad2b71ea5d" /> |
| 74 | <meta-data | 74 | <meta-data |
| 75 | android:name="NewTV.AppSecret" | 75 | android:name="NewTV.AppSecret" |
| 76 | android:value="ec695c7b7371db8dbd84a6d01e4c66a9" /> | 76 | android:value="35199e11ef90c60e51187498e5e4769" /> |
| 77 | 77 | ||
| 78 | <activity | 78 | <activity |
| 79 | android:name="org.cocos2dx.javascript.AppActivity" | 79 | android:name="org.cocos2dx.javascript.AppActivity" | ... | ... |
| ... | @@ -63,6 +63,13 @@ android { | ... | @@ -63,6 +63,13 @@ android { |
| 63 | keyPassword RELEASE_KEY_PASSWORD | 63 | keyPassword RELEASE_KEY_PASSWORD |
| 64 | } | 64 | } |
| 65 | } | 65 | } |
| 66 | |||
| 67 | config { | ||
| 68 | keyAlias 'topdraw' | ||
| 69 | keyPassword 'Topdraw!17qaz' | ||
| 70 | storeFile file('D:/Android/topdraw.keystore') | ||
| 71 | storePassword 'Topdraw!17qaz' | ||
| 72 | } | ||
| 66 | } | 73 | } |
| 67 | 74 | ||
| 68 | buildTypes { | 75 | buildTypes { |
| ... | @@ -74,7 +81,7 @@ android { | ... | @@ -74,7 +81,7 @@ android { |
| 74 | shrinkResources false | 81 | shrinkResources false |
| 75 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | 82 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 76 | if (project.hasProperty("RELEASE_STORE_FILE")) { | 83 | if (project.hasProperty("RELEASE_STORE_FILE")) { |
| 77 | signingConfig signingConfigs.release | 84 | signingConfig signingConfigs.config |
| 78 | } | 85 | } |
| 79 | 86 | ||
| 80 | externalNativeBuild { | 87 | externalNativeBuild { |
| ... | @@ -93,6 +100,7 @@ android { | ... | @@ -93,6 +100,7 @@ android { |
| 93 | arguments 'NDK_DEBUG=1' | 100 | arguments 'NDK_DEBUG=1' |
| 94 | } | 101 | } |
| 95 | } | 102 | } |
| 103 | signingConfig signingConfigs.config | ||
| 96 | } | 104 | } |
| 97 | } | 105 | } |
| 98 | } | 106 | } | ... | ... |
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/libs/armeabi-v7a/libadsdk.so
0 → 100644
No preview for this file type
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/libs/armeabi-v7a/libkystb.so
0 → 100644
No preview for this file type
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/libs/armeabi-v7a/liblogsdk.so
0 → 100644
No preview for this file type
build/jsb-link/frameworks/runtime-src/proj.android-studio/app/libs/armeabi-v7a/libottlogin.so
0 → 100644
No preview for this file type
| ... | @@ -30,7 +30,9 @@ import org.cocos2dx.javascript.component.NewTVSDK; | ... | @@ -30,7 +30,9 @@ import org.cocos2dx.javascript.component.NewTVSDK; |
| 30 | import org.cocos2dx.lib.Cocos2dxActivity; | 30 | import org.cocos2dx.lib.Cocos2dxActivity; |
| 31 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; | 31 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; |
| 32 | 32 | ||
| 33 | import android.app.AlarmManager; | ||
| 33 | import android.app.AlertDialog; | 34 | import android.app.AlertDialog; |
| 35 | import android.app.PendingIntent; | ||
| 34 | import android.content.BroadcastReceiver; | 36 | import android.content.BroadcastReceiver; |
| 35 | import android.content.Context; | 37 | import android.content.Context; |
| 36 | import android.content.DialogInterface; | 38 | import android.content.DialogInterface; |
| ... | @@ -68,11 +70,7 @@ import java.net.URLEncoder; | ... | @@ -68,11 +70,7 @@ import java.net.URLEncoder; |
| 68 | import java.util.HashMap; | 70 | import java.util.HashMap; |
| 69 | import java.util.Map; | 71 | import java.util.Map; |
| 70 | 72 | ||
| 71 | import tv.icntv.adsdk.AdSDK; | ||
| 72 | import tv.icntv.logsdk.logSDK; | ||
| 73 | import tv.icntv.ottlogin.loginSDK; | ||
| 74 | import org.cocos2dx.javascript.component.CocosMediaPlayer; | 73 | import org.cocos2dx.javascript.component.CocosMediaPlayer; |
| 75 | import com.topdraw.forfun.R; | ||
| 76 | import org.cocos2dx.javascript.common.CommonUtils; | 74 | import org.cocos2dx.javascript.common.CommonUtils; |
| 77 | import org.cocos2dx.javascript.common.MelodyApplication; | 75 | import org.cocos2dx.javascript.common.MelodyApplication; |
| 78 | import org.cocos2dx.javascript.common.TopdrawSDKWrapper; | 76 | import org.cocos2dx.javascript.common.TopdrawSDKWrapper; |
| ... | @@ -88,6 +86,7 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -88,6 +86,7 @@ public class AppActivity extends Cocos2dxActivity { |
| 88 | private RelativeLayout relativeLayout; | 86 | private RelativeLayout relativeLayout; |
| 89 | private RelativeLayout mRLSingleColor; | 87 | private RelativeLayout mRLSingleColor; |
| 90 | private RelativeLayout mOBiLayout; | 88 | private RelativeLayout mOBiLayout; |
| 89 | private static String target; | ||
| 91 | 90 | ||
| 92 | public static boolean baminSDKInited = false; | 91 | public static boolean baminSDKInited = false; |
| 93 | public static String APP_KEY; | 92 | public static String APP_KEY; |
| ... | @@ -99,6 +98,7 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -99,6 +98,7 @@ public class AppActivity extends Cocos2dxActivity { |
| 99 | private static String TOPDRAW_PLATFORM_SERVER; | 98 | private static String TOPDRAW_PLATFORM_SERVER; |
| 100 | private static String TOPDRAW_APPID; | 99 | private static String TOPDRAW_APPID; |
| 101 | private static String TOPDRAW_APPSECRET; | 100 | private static String TOPDRAW_APPSECRET; |
| 101 | private static String TOPDRAW_REFER_PATH; | ||
| 102 | 102 | ||
| 103 | public static String TOPDRAW_API_PATH = "http://demo.cloud.api.findfun.topdraw.cn:38081/findfun"; | 103 | public static String TOPDRAW_API_PATH = "http://demo.cloud.api.findfun.topdraw.cn:38081/findfun"; |
| 104 | 104 | ||
| ... | @@ -155,7 +155,7 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -155,7 +155,7 @@ public class AppActivity extends Cocos2dxActivity { |
| 155 | return; | 155 | return; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | CocosMediaPlayer.getInstence(this, CocosMediaPlayer.TYPE.Android); //add jerry | 158 | CocosMediaPlayer.getInstence(this, CocosMediaPlayer.TYPE.NewTV); //add jerry |
| 159 | 159 | ||
| 160 | mUIHandler = new Handler(); | 160 | mUIHandler = new Handler(); |
| 161 | // 显示launch image 遮住「黑屏」 | 161 | // 显示launch image 遮住「黑屏」 |
| ... | @@ -181,8 +181,10 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -181,8 +181,10 @@ public class AppActivity extends Cocos2dxActivity { |
| 181 | TOPDRAW_PLATFORM_SERVER = appInfo.metaData.getString("TOPDRAW.PLATFORM_SERVER"); | 181 | TOPDRAW_PLATFORM_SERVER = appInfo.metaData.getString("TOPDRAW.PLATFORM_SERVER"); |
| 182 | TOPDRAW_APPID = appInfo.metaData.getString("TOPDRAW.APPID"); | 182 | TOPDRAW_APPID = appInfo.metaData.getString("TOPDRAW.APPID"); |
| 183 | TOPDRAW_APPSECRET = appInfo.metaData.getString("TOPDRAW.APPSECRET"); | 183 | TOPDRAW_APPSECRET = appInfo.metaData.getString("TOPDRAW.APPSECRET"); |
| 184 | TOPDRAW_REFER_PATH = TOPDRAW_PLATFORM_SERVER + "/Platform/Logout"; | ||
| 184 | TopdrawSDK.init(getApplicationContext(), TOPDRAW_PLATFORM, TOPDRAW_PLATFORM_SERVER, TOPDRAW_APPID, TOPDRAW_APPSECRET, initListener); | 185 | TopdrawSDK.init(getApplicationContext(), TOPDRAW_PLATFORM, TOPDRAW_PLATFORM_SERVER, TOPDRAW_APPID, TOPDRAW_APPSECRET, initListener); |
| 185 | 186 | ||
| 187 | //移动埋点 | ||
| 186 | APP_KEY = appInfo.metaData.getString("CMCC.APPKEY"); | 188 | APP_KEY = appInfo.metaData.getString("CMCC.APPKEY"); |
| 187 | APP_NAME = getString(R.string.app_name); | 189 | APP_NAME = getString(R.string.app_name); |
| 188 | 190 | ||
| ... | @@ -237,6 +239,20 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -237,6 +239,20 @@ public class AppActivity extends Cocos2dxActivity { |
| 237 | super.onDestroy(); | 239 | super.onDestroy(); |
| 238 | unregisterReceiver(receiver); | 240 | unregisterReceiver(receiver); |
| 239 | SDKWrapper.getInstance().onDestroy(); | 241 | SDKWrapper.getInstance().onDestroy(); |
| 242 | TopdrawSDK.destory(this, null, new ITopdrawResultListener() { | ||
| 243 | @Override | ||
| 244 | public void onResult(int i, String s, Object o) { | ||
| 245 | Log.d(TAG, "destory " + i + " " + s); | ||
| 246 | try { | ||
| 247 | if (baminSDKInited) { | ||
| 248 | SDKUtil.getInstance().ky_quit(); | ||
| 249 | } | ||
| 250 | System.exit(0); | ||
| 251 | } catch (Throwable t) { | ||
| 252 | |||
| 253 | } | ||
| 254 | } | ||
| 255 | }); | ||
| 240 | } | 256 | } |
| 241 | 257 | ||
| 242 | @Override | 258 | @Override |
| ... | @@ -375,10 +391,23 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -375,10 +391,23 @@ public class AppActivity extends Cocos2dxActivity { |
| 375 | private ITopdrawResultListener initListener = new ITopdrawResultListener() { | 391 | private ITopdrawResultListener initListener = new ITopdrawResultListener() { |
| 376 | @Override | 392 | @Override |
| 377 | public void onResult(int result, String msg, Object obj) { | 393 | public void onResult(int result, String msg, Object obj) { |
| 378 | // LOG(TAG, "onResult " + result + " " + msg + " " + obj); | 394 | Log.d(TAG, "onResult " + result + " " + msg + " " + obj);//-1020 init topdraw sdk error null |
| 379 | if (0 == result) { | 395 | if (0 == result) { |
| 380 | MelodyApplication.sdk = (ITopdrawSDK) obj; | 396 | MelodyApplication.sdk = (ITopdrawSDK) obj; |
| 381 | USER_ID = MelodyApplication.sdk.getOssUserID(); | 397 | USER_ID = MelodyApplication.sdk.getOssUserID(); |
| 398 | |||
| 399 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "appId=" + TOPDRAW_APPID); | ||
| 400 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "userId=" + MelodyApplication.sdk.getUserID()); | ||
| 401 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "platformUserId=" + MelodyApplication.sdk.getOssUserID()); | ||
| 402 | try { | ||
| 403 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "referURL=" + URLEncoder.encode(TOPDRAW_REFER_PATH, "UTF-8")); | ||
| 404 | } catch (Exception e) { | ||
| 405 | |||
| 406 | } | ||
| 407 | if (null != target && !"".equals(target)) { | ||
| 408 | CookieManager.getInstance().setCookie(TOPDRAW_PLATFORM_SERVER, "target=" + target); | ||
| 409 | } | ||
| 410 | |||
| 382 | MelodyApplication.isSDKInited = true; | 411 | MelodyApplication.isSDKInited = true; |
| 383 | 412 | ||
| 384 | //局方埋点 | 413 | //局方埋点 |
| ... | @@ -414,11 +443,11 @@ public class AppActivity extends Cocos2dxActivity { | ... | @@ -414,11 +443,11 @@ public class AppActivity extends Cocos2dxActivity { |
| 414 | 443 | ||
| 415 | } | 444 | } |
| 416 | } else if (-1020 == result) { | 445 | } else if (-1020 == result) { |
| 417 | Toast.makeText(AppActivity.this, "网络异常,请重试", Toast.LENGTH_LONG).show(); | 446 | // Toast.makeText(AppActivity.this, "网络异常,请重试", Toast.LENGTH_LONG).show(); |
| 418 | finish(); | 447 | // finish(); |
| 419 | } else { | 448 | } else { |
| 420 | Toast.makeText(AppActivity.this, "启动异常,请重试", Toast.LENGTH_LONG).show(); | 449 | // Toast.makeText(AppActivity.this, "启动异常,请重试", Toast.LENGTH_LONG).show(); |
| 421 | finish(); | 450 | // finish(); |
| 422 | } | 451 | } |
| 423 | } | 452 | } |
| 424 | }; | 453 | }; | ... | ... |
| ... | @@ -11,6 +11,7 @@ import org.cocos2dx.javascript.component.player.AndroidMediaPlayer; | ... | @@ -11,6 +11,7 @@ import org.cocos2dx.javascript.component.player.AndroidMediaPlayer; |
| 11 | //import com.topdraw.component.player.NewTVMediaPlayer; | 11 | //import com.topdraw.component.player.NewTVMediaPlayer; |
| 12 | //import com.topdraw.component.player.VitamioMediaPlayer; | 12 | //import com.topdraw.component.player.VitamioMediaPlayer; |
| 13 | 13 | ||
| 14 | import org.cocos2dx.javascript.component.player.NewTVMediaPlayer; | ||
| 14 | import org.cocos2dx.lib.Cocos2dxActivity; | 15 | import org.cocos2dx.lib.Cocos2dxActivity; |
| 15 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; | 16 | import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge; |
| 16 | 17 | ||
| ... | @@ -102,7 +103,7 @@ public class CocosMediaPlayer { | ... | @@ -102,7 +103,7 @@ public class CocosMediaPlayer { |
| 102 | if (TYPE.Android.name().equals(type)) { | 103 | if (TYPE.Android.name().equals(type)) { |
| 103 | mp = new AndroidMediaPlayer(); | 104 | mp = new AndroidMediaPlayer(); |
| 104 | } else if (TYPE.NewTV.name().equals(type)) { | 105 | } else if (TYPE.NewTV.name().equals(type)) { |
| 105 | // mp = new NewTVMediaPlayer(); | 106 | mp = new NewTVMediaPlayer(); |
| 106 | } else if (TYPE.Vitamio.name().equals(type)) { | 107 | } else if (TYPE.Vitamio.name().equals(type)) { |
| 107 | // mp = new VitamioMediaPlayer(); | 108 | // mp = new VitamioMediaPlayer(); |
| 108 | } else if (TYPE.IJK.name().equals(type)) { | 109 | } else if (TYPE.IJK.name().equals(type)) { | ... | ... |
| ... | @@ -5,6 +5,7 @@ import android.content.pm.ApplicationInfo; | ... | @@ -5,6 +5,7 @@ import android.content.pm.ApplicationInfo; |
| 5 | import android.content.pm.PackageInfo; | 5 | import android.content.pm.PackageInfo; |
| 6 | import android.content.pm.PackageManager; | 6 | import android.content.pm.PackageManager; |
| 7 | import android.os.Handler; | 7 | import android.os.Handler; |
| 8 | import android.util.Log; | ||
| 8 | import android.view.WindowManager; | 9 | import android.view.WindowManager; |
| 9 | import android.widget.FrameLayout; | 10 | import android.widget.FrameLayout; |
| 10 | import android.widget.Toast; | 11 | import android.widget.Toast; |
| ... | @@ -19,6 +20,7 @@ import tv.icntv.ottlogin.loginSDK; | ... | @@ -19,6 +20,7 @@ import tv.icntv.ottlogin.loginSDK; |
| 19 | 20 | ||
| 20 | public class NewTVSDK { | 21 | public class NewTVSDK { |
| 21 | 22 | ||
| 23 | private static final String TAG = "NewTVSDK"; | ||
| 22 | private static NewTVSDK instence; | 24 | private static NewTVSDK instence; |
| 23 | private Context context; | 25 | private Context context; |
| 24 | private PackageInfo packageInfo; | 26 | private PackageInfo packageInfo; |
| ... | @@ -51,12 +53,22 @@ public class NewTVSDK { | ... | @@ -51,12 +53,22 @@ public class NewTVSDK { |
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | loginSDK sdk = loginSDK.getInstance(); | 55 | loginSDK sdk = loginSDK.getInstance(); |
| 54 | String newTVAPPID = appInfo.metaData.getString("NewTV.APPID");; | 56 | //这里的账号返回1003,签名错误 |
| 55 | String newTVChannelCode = appInfo.metaData.getString("NewTV.channelCode"); | 57 | // String newTVAPPID = appInfo.metaData.getString("NewTV.APPID"); |
| 56 | String newTVAppkey = appInfo.metaData.getString("NewTV.Appkey"); | 58 | // String newTVChannelCode = appInfo.metaData.getString("NewTV.channelCode"); |
| 57 | String newTVAppSecret =appInfo.metaData.getString("NewTV.AppSecret"); | 59 | // String newTVAppkey = appInfo.metaData.getString("NewTV.Appkey"); |
| 58 | sdk.sdkInit(loginSDK.TYPE_COMMON, newTVChannelCode, newTVAppkey, newTVAppSecret, context); | 60 | // String newTVAppSecret = appInfo.metaData.getString("NewTV.AppSecret"); |
| 61 | // String newTVAPPID = "4bf34d0e9acf4aa"; | ||
| 62 | // String newTVChannelCode = "2626046001"; | ||
| 63 | // String newTVAppkey = "2e535b79fc515eb17c3c2039517d6c27"; | ||
| 64 | // String newTVAppSecret = "4160dcc2d67eecea0410dc770856d3ae"; | ||
| 65 | String newTVAPPID = "0e0777adb659479"; //东成私塾 | ||
| 66 | String newTVChannelCode = "2626035001"; | ||
| 67 | String newTVAppkey = "df4fc19c4673bf9b5e70a7a56ece35e5"; | ||
| 68 | String newTVAppSecret = "ec695c7b7371db8dbd84a6d01e4c66a9"; | ||
| 69 | boolean flag=sdk.sdkInit(loginSDK.TYPE_COMMON, newTVChannelCode, newTVAppkey, newTVAppSecret, context);//初始化是成功的 | ||
| 59 | String retDeviceLogin = sdk.deviceLogin(); | 70 | String retDeviceLogin = sdk.deviceLogin(); |
| 71 | Log.d("NewTVSDK", flag+" init->deviceLogin..." + sdk.toString()); | ||
| 60 | logSDK logsdk; | 72 | logSDK logsdk; |
| 61 | AdSDK adsdk = null; | 73 | AdSDK adsdk = null; |
| 62 | ADFrameLayout adfl = null; | 74 | ADFrameLayout adfl = null; |
| ... | @@ -64,6 +76,7 @@ public class NewTVSDK { | ... | @@ -64,6 +76,7 @@ public class NewTVSDK { |
| 64 | if ("1".equals(retDeviceLogin) || "766".equals(retDeviceLogin) || "777".equals(retDeviceLogin) || "891".equals(retDeviceLogin)) { | 76 | if ("1".equals(retDeviceLogin) || "766".equals(retDeviceLogin) || "777".equals(retDeviceLogin) || "891".equals(retDeviceLogin)) { |
| 65 | StringBuffer sbDeviceID = new StringBuffer(); | 77 | StringBuffer sbDeviceID = new StringBuffer(); |
| 66 | int retDeviceID = sdk.getDeviceID(sbDeviceID); | 78 | int retDeviceID = sdk.getDeviceID(sbDeviceID); |
| 79 | Log.d(TAG,"init->deviceID"+sbDeviceID.toString()); | ||
| 67 | if (0 == retDeviceID) { | 80 | if (0 == retDeviceID) { |
| 68 | StringBuffer sbLogServer = new StringBuffer(); | 81 | StringBuffer sbLogServer = new StringBuffer(); |
| 69 | int getLogServer = sdk.getServerAddress("USER_LOG", sbLogServer); | 82 | int getLogServer = sdk.getServerAddress("USER_LOG", sbLogServer); | ... | ... |
| 1 | //package com.topdraw.component.player; | 1 | package org.cocos2dx.javascript.component.player; |
| 2 | // | 2 | |
| 3 | //import android.content.Context; | 3 | import android.content.Context; |
| 4 | //import android.media.AudioManager; | 4 | import android.media.AudioManager; |
| 5 | //import android.os.Handler; | 5 | import android.os.Handler; |
| 6 | //import android.util.Log; | 6 | import android.util.Log; |
| 7 | //import android.widget.FrameLayout; | 7 | import android.widget.FrameLayout; |
| 8 | // | 8 | |
| 9 | //import CocosMediaPlayer; | 9 | import org.cocos2dx.javascript.component.CocosMediaPlayer; |
| 10 | //import IMediaPlayer; | 10 | import org.cocos2dx.javascript.component.IMediaPlayer; |
| 11 | // | 11 | import org.json.JSONException; |
| 12 | //import org.json.JSONException; | 12 | import org.json.JSONObject; |
| 13 | //import org.json.JSONObject; | 13 | |
| 14 | // | 14 | import tv.icntv.been.IcntvPlayerInfo; |
| 15 | //import tv.icntv.been.IcntvPlayerInfo; | 15 | import tv.icntv.icntvplayersdk.IcntvPlayer; |
| 16 | //import tv.icntv.icntvplayersdk.IcntvPlayer; | 16 | import tv.icntv.icntvplayersdk.iICntvPlayInterface; |
| 17 | //import tv.icntv.icntvplayersdk.iICntvPlayInterface; | 17 | |
| 18 | // | 18 | public class NewTVMediaPlayer implements IMediaPlayer { |
| 19 | //public class NewTVMediaPlayer implements IMediaPlayer { | 19 | |
| 20 | // | 20 | private Context context; |
| 21 | // private Context context; | 21 | private Handler handler; |
| 22 | // private Handler handler; | 22 | |
| 23 | // | 23 | private FrameLayout fl; |
| 24 | // private FrameLayout fl; | 24 | private IcntvPlayer mp; |
| 25 | // private IcntvPlayer mp; | 25 | private IcntvPlayerInfo info; |
| 26 | // private IcntvPlayerInfo info; | 26 | private JSONObject jsonInfo; |
| 27 | // private JSONObject jsonInfo; | 27 | |
| 28 | // | 28 | @Override |
| 29 | // @Override | 29 | public void init(Context context, FrameLayout rootView, Handler handler) { |
| 30 | // public void init(Context context, FrameLayout rootView, Handler handler) { | 30 | this.context = context; |
| 31 | // this.context = context; | 31 | this.handler = handler; |
| 32 | // this.handler = handler; | 32 | fl = new FrameLayout(context); |
| 33 | // fl = new FrameLayout(context); | 33 | rootView.addView(fl, 0); |
| 34 | // rootView.addView(fl, 0); | 34 | info = new IcntvPlayerInfo(); |
| 35 | // info = new IcntvPlayerInfo(); | 35 | } |
| 36 | // } | 36 | |
| 37 | // | 37 | @Override |
| 38 | // @Override | 38 | public void setArea(int x, int y, int w, int h) { |
| 39 | // public void setArea(int x, int y, int w, int h) { | 39 | FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(w, h); |
| 40 | // FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(w, h); | 40 | flp.leftMargin = x; |
| 41 | // flp.leftMargin = x; | 41 | flp.topMargin = y; |
| 42 | // flp.topMargin = y; | 42 | fl.setLayoutParams(flp); |
| 43 | // fl.setLayoutParams(flp); | 43 | } |
| 44 | // } | 44 | |
| 45 | // | 45 | @Override |
| 46 | // @Override | 46 | public void setPlayURL(String url) { |
| 47 | // public void setPlayURL(String url) { | 47 | info.setPlayUrl(url); |
| 48 | // info.setPlayUrl(url); | 48 | } |
| 49 | // } | 49 | |
| 50 | // | 50 | @Override |
| 51 | // @Override | 51 | public void setInfo(String info) { |
| 52 | // public void setInfo(String info) { | 52 | try { |
| 53 | // try { | 53 | jsonInfo = new JSONObject(info); |
| 54 | // jsonInfo = new JSONObject(info); | 54 | } catch (JSONException e) { |
| 55 | // } catch (JSONException e) { | 55 | e.printStackTrace(); |
| 56 | // e.printStackTrace(); | 56 | } |
| 57 | // } | 57 | } |
| 58 | // } | 58 | |
| 59 | // | 59 | @Override |
| 60 | // @Override | 60 | public void prepare() { |
| 61 | // public void prepare() { | 61 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_PREPARED).sendToTarget(); |
| 62 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_PREPARED).sendToTarget(); | 62 | } |
| 63 | // } | 63 | |
| 64 | // | 64 | @Override |
| 65 | // @Override | 65 | public void prepareAsync() { |
| 66 | // public void prepareAsync() { | 66 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_PREPARED).sendToTarget(); |
| 67 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_PREPARED).sendToTarget(); | 67 | } |
| 68 | // } | 68 | |
| 69 | // | 69 | @Override |
| 70 | // @Override | 70 | public void start() { |
| 71 | // public void start() { | 71 | try { |
| 72 | // try { | 72 | info.setApp_id(jsonInfo.getString("appId")); |
| 73 | // info.setApp_id(jsonInfo.getString("appId")); | 73 | info.setCheckType("program"); |
| 74 | // info.setCheckType("program"); | 74 | info.setPlayUrl(jsonInfo.getString("playURL")); |
| 75 | // info.setPlayUrl(jsonInfo.getString("playURL")); | 75 | info.setProgramID(jsonInfo.getString("fileCode")); |
| 76 | // info.setProgramID(jsonInfo.getString("fileCode")); | 76 | // info.setProgramListID(jsonInfo.getString("mediaCode")); |
| 77 | //// info.setProgramListID(jsonInfo.getString("mediaCode")); | 77 | info.setProgramListID(""); |
| 78 | // info.setProgramListID(""); | 78 | info.setDuration(jsonInfo.getInt("duration")); |
| 79 | // info.setDuration(jsonInfo.getInt("duration")); | 79 | mp = new IcntvPlayer(context, fl, info, iICntvPlayInterface); |
| 80 | // mp = new IcntvPlayer(context, fl, info, iICntvPlayInterface); | 80 | } catch (JSONException e) { |
| 81 | // } catch (JSONException e) { | 81 | e.printStackTrace(); |
| 82 | // e.printStackTrace(); | 82 | } |
| 83 | // } | 83 | } |
| 84 | // } | 84 | |
| 85 | // | 85 | @Override |
| 86 | // @Override | 86 | public void pause() { |
| 87 | // public void pause() { | 87 | if (null != mp) { |
| 88 | // if (null != mp) { | 88 | mp.pauseVideo(); |
| 89 | // mp.pauseVideo(); | 89 | } |
| 90 | // } | 90 | } |
| 91 | // } | 91 | |
| 92 | // | 92 | @Override |
| 93 | // @Override | 93 | public void resume() { |
| 94 | // public void resume() { | 94 | if (null != mp) { |
| 95 | // if (null != mp) { | 95 | mp.startVideo(); |
| 96 | // mp.startVideo(); | 96 | } |
| 97 | // } | 97 | } |
| 98 | // } | 98 | |
| 99 | // | 99 | @Override |
| 100 | // @Override | 100 | public void seekTo(int time) { |
| 101 | // public void seekTo(int time) { | 101 | if (null != mp) { |
| 102 | // if (null != mp) { | 102 | // if (time > 0) { //这里可能是造成快进快退进度条闪跳回几秒的原因 fix jerry |
| 103 | //// if (time > 0) { //这里可能是造成快进快退进度条闪跳回几秒的原因 fix jerry | 103 | mp.seekTo(time); |
| 104 | // mp.seekTo(time); | 104 | // } |
| 105 | //// } | 105 | } |
| 106 | // } | 106 | } |
| 107 | // } | 107 | |
| 108 | // | 108 | @Override |
| 109 | // @Override | 109 | public void setVolume(int volume) { |
| 110 | // public void setVolume(int volume) { | 110 | AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| 111 | // AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); | 111 | if (null != am) { |
| 112 | // if (null != am) { | 112 | int v = Double.valueOf(Math.round(1.0 * volume / 100 * |
| 113 | // int v = Double.valueOf(Math.round(1.0 * volume / 100 * | 113 | am.getStreamMaxVolume(AudioManager.STREAM_MUSIC))).intValue(); |
| 114 | // am.getStreamMaxVolume(AudioManager.STREAM_MUSIC))).intValue(); | 114 | am.setStreamVolume(AudioManager.STREAM_MUSIC, v, AudioManager.FLAG_PLAY_SOUND); |
| 115 | // am.setStreamVolume(AudioManager.STREAM_MUSIC, v, AudioManager.FLAG_PLAY_SOUND); | 115 | } |
| 116 | // } | 116 | } |
| 117 | // } | 117 | |
| 118 | // | 118 | @Override |
| 119 | // @Override | 119 | public void setVolume(float leftVolume, float rightVolume) { |
| 120 | // public void setVolume(float leftVolume, float rightVolume) { | 120 | |
| 121 | // | 121 | } |
| 122 | // } | 122 | |
| 123 | // | 123 | @Override |
| 124 | // @Override | 124 | public void stop() { |
| 125 | // public void stop() { | 125 | if (null != mp) { |
| 126 | // if (null != mp) { | 126 | Log.d("NewTVMediaPlayer","stop..."); |
| 127 | // Log.d("NewTVMediaPlayer","stop..."); | 127 | mp.release(); |
| 128 | // mp.release(); | 128 | mp.quit(); |
| 129 | // mp.quit(); | 129 | mp = null; |
| 130 | // mp = null; | 130 | } |
| 131 | // } | 131 | } |
| 132 | // } | 132 | |
| 133 | // | 133 | @Override |
| 134 | // @Override | 134 | public void reset() { |
| 135 | // public void reset() { | 135 | |
| 136 | // | 136 | } |
| 137 | // } | 137 | |
| 138 | // | 138 | @Override |
| 139 | // @Override | 139 | public void release() { |
| 140 | // public void release() { | 140 | |
| 141 | // | 141 | } |
| 142 | // } | 142 | |
| 143 | // | 143 | @Override |
| 144 | // @Override | 144 | public int getDuration() { |
| 145 | // public int getDuration() { | 145 | int duration = 0; |
| 146 | // int duration = 0; | 146 | if (null != mp) { |
| 147 | // if (null != mp) { | 147 | duration = mp.getDuration(); |
| 148 | // duration = mp.getDuration(); | 148 | } |
| 149 | // } | 149 | return duration; |
| 150 | // return duration; | 150 | } |
| 151 | // } | 151 | |
| 152 | // | 152 | @Override |
| 153 | // @Override | 153 | public int getCurrentPosition() { |
| 154 | // public int getCurrentPosition() { | 154 | int currentPosition = 0; |
| 155 | // int currentPosition = 0; | 155 | if (null != mp) { |
| 156 | // if (null != mp) { | 156 | currentPosition = mp.getCurrentPosition(); |
| 157 | // currentPosition = mp.getCurrentPosition(); | 157 | } |
| 158 | // } | 158 | return currentPosition; |
| 159 | // return currentPosition; | 159 | } |
| 160 | // } | 160 | |
| 161 | // | 161 | @Override |
| 162 | // @Override | 162 | public int getVolume() { |
| 163 | // public int getVolume() { | 163 | int volume = 0; |
| 164 | // int volume = 0; | 164 | AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| 165 | // AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); | 165 | if (null != am) { |
| 166 | // if (null != am) { | 166 | int currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC); |
| 167 | // int currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC); | 167 | int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); |
| 168 | // int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC); | 168 | volume = Double.valueOf(100.0 * currentVolume / maxVolume).intValue(); |
| 169 | // volume = Double.valueOf(100.0 * currentVolume / maxVolume).intValue(); | 169 | } |
| 170 | // } | 170 | return volume; |
| 171 | // return volume; | 171 | } |
| 172 | // } | 172 | |
| 173 | // | 173 | @Override |
| 174 | // @Override | 174 | public boolean isPlaying() { |
| 175 | // public boolean isPlaying() { | 175 | boolean isPlaying = false; |
| 176 | // boolean isPlaying = false; | 176 | if (null != mp) { |
| 177 | // if (null != mp) { | 177 | isPlaying = mp.isPlaying(); |
| 178 | // isPlaying = mp.isPlaying(); | 178 | } |
| 179 | // } | 179 | return isPlaying; |
| 180 | // return isPlaying; | 180 | } |
| 181 | // } | 181 | |
| 182 | // | 182 | private iICntvPlayInterface iICntvPlayInterface = new iICntvPlayInterface() { |
| 183 | // private iICntvPlayInterface iICntvPlayInterface = new iICntvPlayInterface() { | 183 | |
| 184 | // | 184 | @Override |
| 185 | // @Override | 185 | public void onPrepared() { |
| 186 | // public void onPrepared() { | 186 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_STATE_CHANGE, CocosMediaPlayer.MP_STATE_PLAYING).sendToTarget(); |
| 187 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_STATE_CHANGE, CocosMediaPlayer.MP_STATE_PLAYING).sendToTarget(); | 187 | } |
| 188 | // } | 188 | |
| 189 | // | 189 | @Override |
| 190 | // @Override | 190 | public void onCompletion() { |
| 191 | // public void onCompletion() { | 191 | stop(); |
| 192 | // stop(); | 192 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_COMPLETION).sendToTarget(); |
| 193 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_COMPLETION).sendToTarget(); | 193 | } |
| 194 | // } | 194 | |
| 195 | // | 195 | @Override |
| 196 | // @Override | 196 | public void onBufferStart(String s) { |
| 197 | // public void onBufferStart(String s) { | 197 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_BUFFERSTART, s).sendToTarget(); |
| 198 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_BUFFERSTART, s).sendToTarget(); | 198 | } |
| 199 | // } | 199 | |
| 200 | // | 200 | @Override |
| 201 | // @Override | 201 | public void onBufferEnd(String s) { |
| 202 | // public void onBufferEnd(String s) { | 202 | if (iICntvPlayInterface.ON_BUFFER_END_TYPE_AD_ONPREPARED.equals(s)) { |
| 203 | // if (iICntvPlayInterface.ON_BUFFER_END_TYPE_AD_ONPREPARED.equals(s)) { | 203 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_STATE_CHANGE, CocosMediaPlayer.MP_STATE_AD_PLAYING).sendToTarget(); |
| 204 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_STATE_CHANGE, CocosMediaPlayer.MP_STATE_AD_PLAYING).sendToTarget(); | 204 | } else { |
| 205 | // } else { | 205 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_BUFFEREND, s).sendToTarget(); |
| 206 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_BUFFEREND, s).sendToTarget(); | 206 | } |
| 207 | // } | 207 | } |
| 208 | // } | 208 | |
| 209 | // | 209 | @Override |
| 210 | // @Override | 210 | public void onError(int what, int extra, String msg) { |
| 211 | // public void onError(int what, int extra, String msg) { | 211 | Object[] obj = new Object[3]; |
| 212 | // Object[] obj = new Object[3]; | 212 | obj[0] = what; |
| 213 | // obj[0] = what; | 213 | obj[1] = extra; |
| 214 | // obj[1] = extra; | 214 | obj[2] = msg; |
| 215 | // obj[2] = msg; | 215 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_ERROR, obj).sendToTarget(); |
| 216 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_ERROR, obj).sendToTarget(); | 216 | |
| 217 | // | 217 | } |
| 218 | // } | 218 | |
| 219 | // | 219 | @Override |
| 220 | // @Override | 220 | public void onTimeout() { |
| 221 | // public void onTimeout() { | 221 | handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_TIMEOUT).sendToTarget(); |
| 222 | // handler.obtainMessage(CocosMediaPlayer.MP_EVENT_ON_TIMEOUT).sendToTarget(); | 222 | } |
| 223 | // } | 223 | }; |
| 224 | // }; | 224 | } |
| 225 | //} | ... | ... |
-
Please register or sign in to post a comment