diff --git a/PLDroidPlayerDemo/app/build.gradle b/PLDroidPlayerDemo/app/build.gradle index 24c5f1a..50fa023 100644 --- a/PLDroidPlayerDemo/app/build.gradle +++ b/PLDroidPlayerDemo/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion "24.0.0 rc1" + compileSdkVersion 22 + buildToolsVersion "22.0.1" defaultConfig { applicationId "com.pili.pldroid.playerdemo" minSdkVersion 9 - targetSdkVersion 23 + targetSdkVersion 22 versionCode 1 versionName "1.0" } @@ -20,6 +20,7 @@ android { } dependencies { - compile 'com.android.support:design:23.2.1' - compile files('libs/pldroid-player-1.2.3.jar') + compile 'com.android.support:appcompat-v7:22+' + compile files('libs/pldroid-player-1.3.0.jar') + compile 'com.qiniu:happy-dns:0.2.+' } diff --git a/PLDroidPlayerDemo/app/libs/pldroid-player-1.2.3.jar b/PLDroidPlayerDemo/app/libs/pldroid-player-1.3.0.jar similarity index 63% rename from PLDroidPlayerDemo/app/libs/pldroid-player-1.2.3.jar rename to PLDroidPlayerDemo/app/libs/pldroid-player-1.3.0.jar index f38549c..25748e0 100644 Binary files a/PLDroidPlayerDemo/app/libs/pldroid-player-1.2.3.jar and b/PLDroidPlayerDemo/app/libs/pldroid-player-1.3.0.jar differ diff --git a/PLDroidPlayerDemo/app/src/main/AndroidManifest.xml b/PLDroidPlayerDemo/app/src/main/AndroidManifest.xml index cdacbcc..43145d9 100644 --- a/PLDroidPlayerDemo/app/src/main/AndroidManifest.xml +++ b/PLDroidPlayerDemo/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ + adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, TEST_ACTIVITY_ARRAY); mActivitySpinner.setAdapter(adapter); } - public void onClickPlaySetting(View v) { - showPlaySettingDialog(); + @Override + protected void onDestroy() { + super.onDestroy(); + PLNetworkManager.getInstance().stopDnsCacheService(this); } public void onClickLocalFile(View v) { @@ -77,7 +94,16 @@ public void jumpToPlayerActivity(String videopath) { } Intent intent = new Intent(this, cls); intent.putExtra("videoPath", videopath); - intent.putExtra("mediaCodec", mIsHwCodecEnabled); + if (mDecodeTypeRadioGroup.getCheckedRadioButtonId() == R.id.RadioHWDecode) { + intent.putExtra("mediaCodec", 1); + } else { + intent.putExtra("mediaCodec", 0); + } + if (mStreamingTypeRadioGroup.getCheckedRadioButtonId() == R.id.RadioLiveStreaming) { + intent.putExtra("liveStreaming", 1); + } else { + intent.putExtra("liveStreaming", 0); + } startActivity(intent); } @@ -89,32 +115,4 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { String videoPath = data.getStringExtra("videoPath"); mEditText.setText(videoPath, TextView.BufferType.EDITABLE); } - - protected void showPlaySettingDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - final View root = inflater.inflate(R.layout.dialog_setting,null); - final Spinner codecSpinner = (Spinner) root.findViewById(R.id.CodecSpinner); - codecSpinner.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, new String[] { - getString(R.string.sw_decode), getString(R.string.hw_decode) - })); - codecSpinner.setSelection(mIsHwCodecEnabled); - builder.setTitle(getString(R.string.play_setting)); - builder.setView(root); - final AlertDialog dialog = builder.create(); - dialog.setCancelable(false); - dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dlg_ok), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mIsHwCodecEnabled = codecSpinner.getSelectedItemPosition(); - } - }); - dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dlg_cancel), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - } - }); - dialog.show(); - } } diff --git a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLAudioPlayerActivity.java b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLAudioPlayerActivity.java index bfd3df0..a685afa 100644 --- a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLAudioPlayerActivity.java +++ b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLAudioPlayerActivity.java @@ -173,6 +173,12 @@ public boolean onError(PLMediaPlayer mp, int errorCode) { break; case PLMediaPlayer.ERROR_CODE_STREAM_DISCONNECTED: break; + case PLMediaPlayer.ERROR_CODE_UNAUTHORIZED: + break; + case PLMediaPlayer.ERROR_CODE_PREPARE_TIMEOUT: + break; + case PLMediaPlayer.ERROR_CODE_READ_FRAME_TIMEOUT: + break; case PLMediaPlayer.MEDIA_ERROR_UNKNOWN: break; default: diff --git a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLMediaPlayerActivity.java b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLMediaPlayerActivity.java index e87213e..f5d7810 100644 --- a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLMediaPlayerActivity.java +++ b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLMediaPlayerActivity.java @@ -51,12 +51,14 @@ protected void onCreate(Bundle savedInstanceState) { mAVOptions = new AVOptions(); - if (isLiveStreaming(mVideoPath)) { - // the unit of timeout is ms - mAVOptions.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000); - mAVOptions.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000); - // Some optimization with buffering mechanism when be set to 1 - mAVOptions.setInteger(AVOptions.KEY_LIVE_STREAMING, 1); + int isLiveStreaming = getIntent().getIntExtra("liveStreaming", 1); + // the unit of timeout is ms + mAVOptions.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000); + mAVOptions.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000); + // Some optimization with buffering mechanism when be set to 1 + mAVOptions.setInteger(AVOptions.KEY_LIVE_STREAMING, isLiveStreaming); + if (isLiveStreaming == 1) { + mAVOptions.setInteger(AVOptions.KEY_DELAY_OPTIMIZATION, 1); } // 1 -> hw codec enable, 0 -> disable [recommended] @@ -116,6 +118,7 @@ public void onClickStop(View v) { mMediaPlayer.reset(); } mIsStopped = true; + mMediaPlayer = null; } public void releaseWithoutStop() { @@ -283,6 +286,15 @@ public boolean onError(PLMediaPlayer mp, int errorCode) { case PLMediaPlayer.ERROR_CODE_IO_ERROR: showToastTips("Network IO Error !"); break; + case PLMediaPlayer.ERROR_CODE_UNAUTHORIZED: + showToastTips("Unauthorized Error !"); + break; + case PLMediaPlayer.ERROR_CODE_PREPARE_TIMEOUT: + showToastTips("Prepare timeout !"); + break; + case PLMediaPlayer.ERROR_CODE_READ_FRAME_TIMEOUT: + showToastTips("Read frame timeout !"); + break; case PLMediaPlayer.MEDIA_ERROR_UNKNOWN: default: showToastTips("unknown error !"); @@ -316,13 +328,4 @@ public void run() { } }); } - - private boolean isLiveStreaming(String url) { - if (url.startsWith("rtmp://") - || (url.startsWith("http://") && url.endsWith(".m3u8")) - || (url.startsWith("http://") && url.endsWith(".flv"))) { - return true; - } - return false; - } } diff --git a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoTextureActivity.java b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoTextureActivity.java index 0531350..57a1587 100644 --- a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoTextureActivity.java +++ b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoTextureActivity.java @@ -48,12 +48,14 @@ protected void onCreate(Bundle savedInstanceState) { AVOptions options = new AVOptions(); - if (isLiveStreaming(mVideoPath)) { - // the unit of timeout is ms - options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000); - options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000); - // Some optimization with buffering mechanism when be set to 1 - options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1); + int isLiveStreaming = getIntent().getIntExtra("liveStreaming", 1); + // the unit of timeout is ms + options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000); + options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000); + // Some optimization with buffering mechanism when be set to 1 + options.setInteger(AVOptions.KEY_LIVE_STREAMING, isLiveStreaming); + if (isLiveStreaming == 1) { + options.setInteger(AVOptions.KEY_DELAY_OPTIMIZATION, 1); } // 1 -> hw codec enable, 0 -> disable [recommended] @@ -69,7 +71,7 @@ protected void onCreate(Bundle savedInstanceState) { // mVideoView.setMirror(true); // You can also use a custom `MediaController` widget - mMediaController = new MediaController(this, false, isLiveStreaming(mVideoPath)); + mMediaController = new MediaController(this, false, isLiveStreaming == 1); mVideoView.setMediaController(mMediaController); mVideoView.setOnCompletionListener(mOnCompletionListener); @@ -152,6 +154,15 @@ public boolean onError(PLMediaPlayer mp, int errorCode) { case PLMediaPlayer.ERROR_CODE_IO_ERROR: showToastTips("Network IO Error !"); break; + case PLMediaPlayer.ERROR_CODE_UNAUTHORIZED: + showToastTips("Unauthorized Error !"); + break; + case PLMediaPlayer.ERROR_CODE_PREPARE_TIMEOUT: + showToastTips("Prepare timeout !"); + break; + case PLMediaPlayer.ERROR_CODE_READ_FRAME_TIMEOUT: + showToastTips("Read frame timeout !"); + break; case PLMediaPlayer.MEDIA_ERROR_UNKNOWN: default: showToastTips("unknown error !"); @@ -188,13 +199,4 @@ public void run() { } }); } - - private boolean isLiveStreaming(String url) { - if (url.startsWith("rtmp://") - || (url.startsWith("http://") && url.endsWith(".m3u8")) - || (url.startsWith("http://") && url.endsWith(".flv"))) { - return true; - } - return false; - } } diff --git a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoViewActivity.java b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoViewActivity.java index f34bf26..44754b1 100644 --- a/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoViewActivity.java +++ b/PLDroidPlayerDemo/app/src/main/java/com/pili/pldroid/playerdemo/PLVideoViewActivity.java @@ -40,12 +40,14 @@ protected void onCreate(Bundle savedInstanceState) { AVOptions options = new AVOptions(); - if (isLiveStreaming(mVideoPath)) { - // the unit of timeout is ms - options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000); - options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000); - // Some optimization with buffering mechanism when be set to 1 - options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1); + int isLiveStreaming = getIntent().getIntExtra("liveStreaming", 1); + // the unit of timeout is ms + options.setInteger(AVOptions.KEY_PREPARE_TIMEOUT, 10 * 1000); + options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000); + // Some optimization with buffering mechanism when be set to 1 + options.setInteger(AVOptions.KEY_LIVE_STREAMING, isLiveStreaming); + if (isLiveStreaming == 1) { + options.setInteger(AVOptions.KEY_DELAY_OPTIMIZATION, 1); } // 1 -> hw codec enable, 0 -> disable [recommended] @@ -68,7 +70,7 @@ protected void onCreate(Bundle savedInstanceState) { mVideoView.setVideoPath(mVideoPath); // You can also use a custom `MediaController` widget - mMediaController = new MediaController(this, false, isLiveStreaming(mVideoPath)); + mMediaController = new MediaController(this, false, isLiveStreaming == 1); mVideoView.setMediaController(mMediaController); } @@ -151,6 +153,15 @@ public boolean onError(PLMediaPlayer plMediaPlayer, int errorCode) { case PLMediaPlayer.ERROR_CODE_IO_ERROR: showToastTips("Network IO Error !"); break; + case PLMediaPlayer.ERROR_CODE_UNAUTHORIZED: + showToastTips("Unauthorized Error !"); + break; + case PLMediaPlayer.ERROR_CODE_PREPARE_TIMEOUT: + showToastTips("Prepare timeout !"); + break; + case PLMediaPlayer.ERROR_CODE_READ_FRAME_TIMEOUT: + showToastTips("Read frame timeout !"); + break; case PLMediaPlayer.MEDIA_ERROR_UNKNOWN: default: showToastTips("unknown error !"); @@ -212,13 +223,4 @@ public void run() { } }); } - - private boolean isLiveStreaming(String url) { - if (url.startsWith("rtmp://") - || (url.startsWith("http://") && url.endsWith(".m3u8")) - || (url.startsWith("http://") && url.endsWith(".flv"))) { - return true; - } - return false; - } } diff --git a/PLDroidPlayerDemo/app/src/main/jniLibs/arm64-v8a/libpldroidplayer.so b/PLDroidPlayerDemo/app/src/main/jniLibs/arm64-v8a/libpldroidplayer.so index db4252f..551626b 100755 Binary files a/PLDroidPlayerDemo/app/src/main/jniLibs/arm64-v8a/libpldroidplayer.so and b/PLDroidPlayerDemo/app/src/main/jniLibs/arm64-v8a/libpldroidplayer.so differ diff --git a/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi-v7a/libpldroidplayer.so b/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi-v7a/libpldroidplayer.so index e8396d1..67940d4 100755 Binary files a/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi-v7a/libpldroidplayer.so and b/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi-v7a/libpldroidplayer.so differ diff --git a/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi/libpldroidplayer.so b/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi/libpldroidplayer.so index 27f893c..ed6f4d0 100755 Binary files a/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi/libpldroidplayer.so and b/PLDroidPlayerDemo/app/src/main/jniLibs/armeabi/libpldroidplayer.so differ diff --git a/PLDroidPlayerDemo/app/src/main/jniLibs/x86/libpldroidplayer.so b/PLDroidPlayerDemo/app/src/main/jniLibs/x86/libpldroidplayer.so index 502c4ab..b7bfffc 100755 Binary files a/PLDroidPlayerDemo/app/src/main/jniLibs/x86/libpldroidplayer.so and b/PLDroidPlayerDemo/app/src/main/jniLibs/x86/libpldroidplayer.so differ diff --git a/PLDroidPlayerDemo/app/src/main/res/layout/activity_main.xml b/PLDroidPlayerDemo/app/src/main/res/layout/activity_main.xml index dc9f204..40ab824 100644 --- a/PLDroidPlayerDemo/app/src/main/res/layout/activity_main.xml +++ b/PLDroidPlayerDemo/app/src/main/res/layout/activity_main.xml @@ -18,6 +18,62 @@ android:layout_height="wrap_content" android:layout_marginLeft="10dp"/> + + + + + + + + + + + + + + + + + + + + - - - + +