diff --git a/README-ZH.md b/README-ZH.md index cc4a2806f..2752e9a28 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -2,7 +2,7 @@ --

- +

@@ -19,33 +19,33 @@ 5. 视频大小的屏幕适配,宽或长至少有两个对边是充满屏幕的,另外两个方向居中 6. 可以在加载、暂停、播放等各种状态中正常进入全屏和退出全屏 7. [支持hls,rtsp](https://developer.android.com/guide/appendix/media-formats.html) -8. 占用空间非常小,不到60k +8. 占用空间非常小,不到100k 9. 设置http头信息 ##效果 -**[jiecaovideoplayer-3.6.3-demo.apk](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3-demo.apk)** +**[jiecaovideoplayer-4.0_beta-demo.apk](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta-demo.apk)** ![Demo Screenshot][1] ##使用 1.添加类库 ```gradle -compile 'fm.jiecao:jiecaovideoplayer:3.6.3' +compile 'fm.jiecao:jiecaovideoplayer:4.0_beta' ``` 或直接下载 -* [jiecaovideoplayer-3.6.3.aar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3.aar) -* [jiecaovideoplayer-3.6.3-javadoc.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3-javadoc.jar) -* [jiecaovideoplayer-3.6.3-sources.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3-sources.jar) +* [jiecaovideoplayer-4.0_beta.aar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta.aar) +* [jiecaovideoplayer-4.0_beta-javadoc.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta-javadoc.jar) +* [jiecaovideoplayer-4.0_beta-sources.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta-sources.jar) 2.添加布局 ```xml + android:layout_height="200dp"/> ``` 3.设置视频地址、缩略图地址、标题 @@ -82,7 +82,7 @@ jcVideoPlayerStandard.startButton.performClick(); ##贡献者 -[Nathen](https://github.com/lipangit) [Derlio](https://github.com/derlio) [zhangzzqq](https://github.com/zhangzzqq) [carmelo-ruota](https://github.com/carmelo-ruota) [wxxsw](https://github.com/wxxsw) +[Nathen](https://github.com/lipangit) [Derlio](https://github.com/derlio) [zhangzzqq](https://github.com/zhangzzqq) [carmelo-ruota](https://github.com/carmelo-ruota) [wxxsw](https://github.com/wxxsw) [Miguel Aragues](https://github.com/Maragues) ## License MIT diff --git a/README.md b/README.md index c1310b1b2..3279f58ec 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ --

- +

@@ -23,26 +23,26 @@ Android truly full-screen capabilities, the Android platform to become the most 5. Adaptive to the screen size, where at least the width or length of the video is adaptive while the other is centered on the screen 6. It will not disturb or change the playing state when entering or exiting fullscreen 7. [Support hls,rtsp](https://developer.android.com/guide/appendix/media-formats.html) -8. With limited storage, less than 60 kb +8. With limited storage, less than 100k 9. Put head data ## Effect -**[jiecaovideoplayer-3.6.3-demo.apk](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3-demo.apk)** +**[jiecaovideoplayer-4.0_beta-demo.apk](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta-demo.apk)** ![Demo Screenshot][1] ## Usage 1.Import library ```gradle -compile 'fm.jiecao:jiecaovideoplayer:3.6.3' +compile 'fm.jiecao:jiecaovideoplayer:4.0_beta' ``` Or download lib -* [jiecaovideoplayer-3.6.3.aar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3.aar) -* [jiecaovideoplayer-3.6.3-javadoc.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3-javadoc.jar) -* [jiecaovideoplayer-3.6.3-sources.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-3.6.3-sources.jar) +* [jiecaovideoplayer-4.0_beta.aar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta.aar) +* [jiecaovideoplayer-4.0_beta-javadoc.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta-javadoc.jar) +* [jiecaovideoplayer-4.0_beta-sources.jar](https://raw.githubusercontent.com/lipangit/jiecaovideoplayer/develop/downloads/jiecaovideoplayer-4.0_beta-sources.jar) 2.Add JCVideoPlayer in your layout ```xml @@ -86,7 +86,7 @@ Need nothing ##Contributors -[Nathen](https://github.com/lipangit) [Derlio](https://github.com/derlio) [zhangzzqq](https://github.com/zhangzzqq) [carmelo-ruota](https://github.com/carmelo-ruota) [wxxsw](https://github.com/wxxsw) +[Nathen](https://github.com/lipangit) [Derlio](https://github.com/derlio) [zhangzzqq](https://github.com/zhangzzqq) [carmelo-ruota](https://github.com/carmelo-ruota) [wxxsw](https://github.com/wxxsw) [Miguel Aragues](https://github.com/Maragues) ## License MIT diff --git a/app/build.gradle b/app/build.gradle index f10cb18e3..833f75293 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "fm.jiecao.jiecaovideoplayer" minSdkVersion 16 targetSdkVersion 23 - versionCode 31 - versionName "3.6.3" + versionCode 32 + versionName "4.0_beta" } buildTypes { release { @@ -37,4 +37,13 @@ dependencies { releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' + //If you can not start app, you cancel the annotation + //如果app无法启动,请取消下面的注释 + //Other ABIs: optional +// compile 'tv.danmaku.ijk.media:ijkplayer-armv5:0.6.0' + compile 'tv.danmaku.ijk.media:ijkplayer-arm64:0.6.0' + compile 'tv.danmaku.ijk.media:ijkplayer-x86:0.6.0' + compile 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.6.0' + //ExoPlayer as IMediaPlayer: optional, experimental + //compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.6.0' } diff --git a/app/src/main/java/fm/jiecao/jiecaovideoplayer/View/JCVideoPlayerStandardFresco.java b/app/src/main/java/fm/jiecao/jiecaovideoplayer/View/JCVideoPlayerStandardFresco.java index d1b672640..5dd3585a6 100644 --- a/app/src/main/java/fm/jiecao/jiecaovideoplayer/View/JCVideoPlayerStandardFresco.java +++ b/app/src/main/java/fm/jiecao/jiecaovideoplayer/View/JCVideoPlayerStandardFresco.java @@ -24,7 +24,7 @@ import fm.jiecao.jcvideoplayer_lib.JCBuriedPointStandard; import fm.jiecao.jcvideoplayer_lib.JCMediaManager; -import fm.jiecao.jcvideoplayer_lib.Utils; +import fm.jiecao.jcvideoplayer_lib.JCUtils; import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer; import fm.jiecao.jiecaovideoplayer.R; @@ -166,7 +166,7 @@ public void onClick(View v) { return; } if (mCurrentState == CURRENT_STATE_NORMAL) { - if (!Utils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) { + if (!JCUtils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage(getResources().getString(fm.jiecao.jcvideoplayer_lib.R.string.tips_not_wifi)); builder.setPositiveButton(getResources().getString(fm.jiecao.jcvideoplayer_lib.R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() { @@ -191,7 +191,7 @@ public void onClick(DialogInterface dialog, int which) { onClickUiToggle(); } } else if (i == R.id.surface_container) { - if (JC_BURIED_POINT_STANDARD != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT_STANDARD != null && isCurrentMediaListener()) { if (mIfCurrentIsFullscreen) { JC_BURIED_POINT_STANDARD.onClickBlankFullscreen(mUrl, mObjects); } else { diff --git a/downloads/jiecaovideoplayer-3.6.3-demo.apk b/downloads/jiecaovideoplayer-3.6.3-demo.apk deleted file mode 100644 index be50b1431..000000000 Binary files a/downloads/jiecaovideoplayer-3.6.3-demo.apk and /dev/null differ diff --git a/downloads/jiecaovideoplayer-3.6.3-javadoc.jar b/downloads/jiecaovideoplayer-3.6.3-javadoc.jar deleted file mode 100644 index 03b4ca393..000000000 Binary files a/downloads/jiecaovideoplayer-3.6.3-javadoc.jar and /dev/null differ diff --git a/downloads/jiecaovideoplayer-3.6.3-sources.jar b/downloads/jiecaovideoplayer-3.6.3-sources.jar deleted file mode 100644 index a5ff693d4..000000000 Binary files a/downloads/jiecaovideoplayer-3.6.3-sources.jar and /dev/null differ diff --git a/downloads/jiecaovideoplayer-3.6.3.aar b/downloads/jiecaovideoplayer-3.6.3.aar deleted file mode 100644 index 06f25cba1..000000000 Binary files a/downloads/jiecaovideoplayer-3.6.3.aar and /dev/null differ diff --git a/downloads/jiecaovideoplayer-4.0_beta-demo.apk b/downloads/jiecaovideoplayer-4.0_beta-demo.apk new file mode 100644 index 000000000..d93cda1e6 Binary files /dev/null and b/downloads/jiecaovideoplayer-4.0_beta-demo.apk differ diff --git a/downloads/jiecaovideoplayer-4.0_beta-javadoc.jar b/downloads/jiecaovideoplayer-4.0_beta-javadoc.jar new file mode 100644 index 000000000..583a28ec1 Binary files /dev/null and b/downloads/jiecaovideoplayer-4.0_beta-javadoc.jar differ diff --git a/downloads/jiecaovideoplayer-4.0_beta-sources.jar b/downloads/jiecaovideoplayer-4.0_beta-sources.jar new file mode 100644 index 000000000..c44013f14 Binary files /dev/null and b/downloads/jiecaovideoplayer-4.0_beta-sources.jar differ diff --git a/downloads/jiecaovideoplayer-4.0_beta.aar b/downloads/jiecaovideoplayer-4.0_beta.aar new file mode 100644 index 000000000..25e1bc324 Binary files /dev/null and b/downloads/jiecaovideoplayer-4.0_beta.aar differ diff --git a/gradle/maven_push.gradle b/gradle/maven_push.gradle index 553e9e5e9..72a0d6734 100644 --- a/gradle/maven_push.gradle +++ b/gradle/maven_push.gradle @@ -22,7 +22,7 @@ signing { group = "fm.jiecao" archivesBaseName = "jiecaovideoplayer" -version = "3.6.3" +version = "4.0_beta" uploadArchives { repositories { diff --git a/jcvideoplayer-lib/build.gradle b/jcvideoplayer-lib/build.gradle index 9e17980e5..367b14371 100644 --- a/jcvideoplayer-lib/build.gradle +++ b/jcvideoplayer-lib/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 23 - versionCode 31 - versionName "3.6.3" + versionCode 32 + versionName "4.0_beta" } buildTypes { release { @@ -24,6 +24,10 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' + + //required, enough for most devices. + compile 'tv.danmaku.ijk.media:ijkplayer-java:0.6.0' + compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.6.0' } apply from: '../gradle/maven_push.gradle' diff --git a/jcvideoplayer-lib/src/main/AndroidManifest.xml b/jcvideoplayer-lib/src/main/AndroidManifest.xml index 50ee615c8..eb633183a 100644 --- a/jcvideoplayer-lib/src/main/AndroidManifest.xml +++ b/jcvideoplayer-lib/src/main/AndroidManifest.xml @@ -1,7 +1,11 @@ + + diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCFullScreenActivity.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCFullScreenActivity.java index 063e6c25f..7ce25454a 100644 --- a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCFullScreenActivity.java +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCFullScreenActivity.java @@ -87,7 +87,7 @@ protected void onCreate(Bundle savedInstanceState) { mJcVideoPlayer.startButton.performClick(); } else { JCVideoPlayer.IF_RELEASE_WHEN_ON_PAUSE = true; - JCMediaManager.instance().listener = mJcVideoPlayer; + JCMediaManager.instance().setListener(mJcVideoPlayer); if (CURRENT_STATE == JCVideoPlayer.CURRENT_STATE_PAUSE) { JCMediaManager.instance().mediaPlayer.seekTo(JCMediaManager.instance().mediaPlayer.getCurrentPosition()); } diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCMediaManager.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCMediaManager.java index a41c3150c..5a94a34bd 100644 --- a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCMediaManager.java +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCMediaManager.java @@ -1,7 +1,6 @@ package fm.jiecao.jcvideoplayer_lib; import android.media.AudioManager; -import android.media.MediaPlayer; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; @@ -9,10 +8,14 @@ import android.text.TextUtils; import android.view.Surface; +import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; +import tv.danmaku.ijk.media.player.IMediaPlayer; +import tv.danmaku.ijk.media.player.IjkMediaPlayer; + /** *

统一管理MediaPlayer的地方,只有一个mediaPlayer实例,那么不会有多个视频同时播放,也节省资源。

@@ -20,17 +23,15 @@ * Created by Nathen * On 2015/11/30 15:39 */ -public class JCMediaManager implements MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener, - MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnSeekCompleteListener, MediaPlayer.OnErrorListener, - MediaPlayer.OnVideoSizeChangedListener, MediaPlayer.OnInfoListener { +public class JCMediaManager implements IMediaPlayer.OnPreparedListener, IMediaPlayer.OnCompletionListener, + IMediaPlayer.OnBufferingUpdateListener, IMediaPlayer.OnSeekCompleteListener, IMediaPlayer.OnErrorListener, + IMediaPlayer.OnVideoSizeChangedListener, IMediaPlayer.OnInfoListener { public static String TAG = JCVideoPlayer.TAG; - public MediaPlayer mediaPlayer; + public IjkMediaPlayer mediaPlayer; private static JCMediaManager JCMediaManager; public int currentVideoWidth = 0; public int currentVideoHeight = 0; - public JCMediaPlayerListener listener; - public JCMediaPlayerListener lastListener; public int lastState; public static final int HANDLER_PREPARE = 0; @@ -40,6 +41,36 @@ public class JCMediaManager implements MediaPlayer.OnPreparedListener, MediaPlay MediaHandler mMediaHandler; Handler mainThreadHandler; + private WeakReference listener; + private WeakReference lastListener; + + public JCMediaPlayerListener listener() { + if (listener == null) + return null; + return listener.get(); + } + + public JCMediaPlayerListener lastListener() { + if (lastListener == null) + return null; + return lastListener.get(); + } + + public void setListener(JCMediaPlayerListener listener) { + if (listener == null) + this.listener = null; + else + this.listener = new WeakReference<>(listener); + } + + public void setLastListener(JCMediaPlayerListener lastListener) { + if (lastListener == null) + this.lastListener = null; + else + this.lastListener = new WeakReference<>(lastListener); + } + + public static JCMediaManager instance() { if (JCMediaManager == null) { JCMediaManager = new JCMediaManager(); @@ -48,7 +79,7 @@ public static JCMediaManager instance() { } public JCMediaManager() { - mediaPlayer = new MediaPlayer(); + mediaPlayer = new IjkMediaPlayer(); mMediaHandlerThread = new HandlerThread(TAG); mMediaHandlerThread.start(); mMediaHandler = new MediaHandler((mMediaHandlerThread.getLooper())); @@ -69,10 +100,10 @@ public void handleMessage(Message msg) { currentVideoWidth = 0; currentVideoHeight = 0; mediaPlayer.release(); - mediaPlayer = new MediaPlayer(); + mediaPlayer = new IjkMediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); // mediaPlayer.setDataSource(context, Uri.parse(url), mapHeadData); - Class clazz = MediaPlayer.class; + Class clazz = IjkMediaPlayer.class; Method method = clazz.getDeclaredMethod("setDataSource", String.class, Map.class); method.invoke(mediaPlayer, ((FuckBean) msg.obj).url, ((FuckBean) msg.obj).mapHeadData); mediaPlayer.setLooping(((FuckBean) msg.obj).looping); @@ -136,60 +167,60 @@ public void setDisplay(Surface holder) { } @Override - public void onPrepared(MediaPlayer mp) { + public void onPrepared(IMediaPlayer mp) { mainThreadHandler.post(new Runnable() { @Override public void run() { if (listener != null) { - listener.onPrepared(); + listener().onPrepared(); } } }); } @Override - public void onCompletion(MediaPlayer mp) { + public void onCompletion(IMediaPlayer mp) { mainThreadHandler.post(new Runnable() { @Override public void run() { if (listener != null) { - listener.onAutoCompletion(); + listener().onAutoCompletion(); } } }); } @Override - public void onBufferingUpdate(MediaPlayer mp, final int percent) { + public void onBufferingUpdate(IMediaPlayer mp, final int percent) { mainThreadHandler.post(new Runnable() { @Override public void run() { if (listener != null) { - listener.onBufferingUpdate(percent); + listener().onBufferingUpdate(percent); } } }); } @Override - public void onSeekComplete(MediaPlayer mp) { + public void onSeekComplete(IMediaPlayer mp) { mainThreadHandler.post(new Runnable() { @Override public void run() { if (listener != null) { - listener.onSeekComplete(); + listener().onSeekComplete(); } } }); } @Override - public boolean onError(MediaPlayer mp, final int what, final int extra) { + public boolean onError(IMediaPlayer mp, final int what, final int extra) { mainThreadHandler.post(new Runnable() { @Override public void run() { if (listener != null) { - listener.onError(what, extra); + listener().onError(what, extra); } } }); @@ -197,12 +228,12 @@ public void run() { } @Override - public boolean onInfo(MediaPlayer mp, final int what, final int extra) { + public boolean onInfo(IMediaPlayer mp, final int what, final int extra) { mainThreadHandler.post(new Runnable() { @Override public void run() { if (listener != null) { - listener.onInfo(what, extra); + listener().onInfo(what, extra); } } }); @@ -210,14 +241,14 @@ public void run() { } @Override - public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { + public void onVideoSizeChanged(IMediaPlayer mp, int width, int height, int sar_num, int sar_den) { currentVideoWidth = mp.getVideoWidth(); currentVideoHeight = mp.getVideoHeight(); mainThreadHandler.post(new Runnable() { @Override public void run() { if (listener != null) { - listener.onVideoSizeChanged(); + listener().onVideoSizeChanged(); } } }); diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/Utils.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCUtils.java similarity index 98% rename from jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/Utils.java rename to jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCUtils.java index 94c8bdbea..4d92212b5 100644 --- a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/Utils.java +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCUtils.java @@ -11,7 +11,7 @@ * Created by Nathen * On 2016/02/21 12:25 */ -public class Utils { +public class JCUtils { public static String stringForTime(int timeMs) { if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) { diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java index 253b935ca..a560270d9 100644 --- a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java @@ -1,9 +1,7 @@ package fm.jiecao.jcvideoplayer_lib; import android.app.Activity; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.graphics.SurfaceTexture; import android.media.AudioManager; import android.media.MediaPlayer; @@ -70,6 +68,8 @@ public abstract class JCVideoPlayer extends FrameLayout implements View.OnClickL protected Object[] mObjects; protected Map mMapHeadData = new HashMap<>(); protected boolean mLooping = false; + public int seekToInAdvance = -1; + protected static Timer UPDATE_PROGRESS_TIMER; protected ProgressTimerTask mProgressTimerTask; @@ -134,7 +134,7 @@ protected static void setJcBuriedPoint(JCBuriedPoint jcBuriedPoint) { } public boolean setUp(String url, Object... objects) { - if (JCMediaManager.instance().listener == this && + if (isCurrentMediaListener() && (System.currentTimeMillis() - CLICK_QUIT_FULLSCREEN_TIME) < FULL_SCREEN_NORMAL_DELAY) return false; mCurrentState = CURRENT_STATE_NORMAL; @@ -162,7 +162,7 @@ protected void setStateAndUi(int state) { mCurrentState = state; switch (mCurrentState) { case CURRENT_STATE_NORMAL: - if (JCMediaManager.instance().listener == this) { + if (isCurrentMediaListener()) { cancelProgressTimer(); JCMediaManager.instance().releaseMediaPlayer(); } @@ -177,7 +177,7 @@ protected void setStateAndUi(int state) { startProgressTimer(); break; case CURRENT_STATE_ERROR: - if (JCMediaManager.instance().listener == this) { + if (isCurrentMediaListener()) { JCMediaManager.instance().releaseMediaPlayer(); } break; @@ -199,24 +199,8 @@ public void onClick(View v) { return; } if (mCurrentState == CURRENT_STATE_NORMAL || mCurrentState == CURRENT_STATE_ERROR) { - if (!Utils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setMessage(getResources().getString(R.string.tips_not_wifi)); - builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - startButtonLogic(); - WIFI_TIP_DIALOG_SHOWED = true; - } - }); - builder.setNegativeButton(getResources().getString(R.string.tips_not_wifi_cancel), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - builder.create().show(); + if (!mUrl.startsWith("file") && !JCUtils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) { + showWifiDialog(); return; } startButtonLogic(); @@ -224,7 +208,7 @@ public void onClick(DialogInterface dialog, int which) { Log.d(TAG, "pauseVideo [" + this.hashCode() + "] "); JCMediaManager.instance().mediaPlayer.pause(); setStateAndUi(CURRENT_STATE_PAUSE); - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { if (mIfCurrentIsFullscreen) { JC_BURIED_POINT.onClickStopFullscreen(mUrl, mObjects); } else { @@ -232,7 +216,7 @@ public void onClick(DialogInterface dialog, int which) { } } } else if (mCurrentState == CURRENT_STATE_PAUSE) { - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { if (mIfCurrentIsFullscreen) { JC_BURIED_POINT.onClickResumeFullscreen(mUrl, mObjects); } else { @@ -252,13 +236,13 @@ public void onClick(DialogInterface dialog, int which) { backFullscreen(); } else { Log.d(TAG, "toFullscreenActivity [" + this.hashCode() + "] "); - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { JC_BURIED_POINT.onEnterFullscreen(mUrl, mObjects); } //to fullscreen JCMediaManager.instance().setDisplay(null); - JCMediaManager.instance().lastListener = this; - JCMediaManager.instance().listener = null; + JCMediaManager.instance().setLastListener(this); + JCMediaManager.instance().setListener(null); IF_FULLSCREEN_FROM_NORMAL = true; IF_RELEASE_WHEN_ON_PAUSE = false; JCFullScreenActivity.startActivityFromNormal(getContext(), mCurrentState, mUrl, JCVideoPlayer.this.getClass(), this.mObjects); @@ -272,6 +256,10 @@ public void onClick(DialogInterface dialog, int which) { } } + public void showWifiDialog() { + + } + private void startButtonLogic() { if (JC_BURIED_POINT != null && mCurrentState == CURRENT_STATE_NORMAL) { JC_BURIED_POINT.onClickStartIcon(mUrl, mObjects); @@ -283,10 +271,10 @@ private void startButtonLogic() { protected void prepareVideo() { Log.d(TAG, "prepareVideo [" + this.hashCode() + "] "); - if (JCMediaManager.instance().listener != null) { - JCMediaManager.instance().listener.onCompletion(); + if (JCMediaManager.instance().listener() != null) { + JCMediaManager.instance().listener().onCompletion(); } - JCMediaManager.instance().listener = this; + JCMediaManager.instance().setListener(this); addTextureView(); AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); @@ -383,13 +371,13 @@ public boolean onTouch(View v, MotionEvent event) { if (absDeltaX >= mThreshold) { mChangePosition = true; mDownPosition = getCurrentPositionWhenPlaying(); - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { JC_BURIED_POINT.onTouchScreenSeekPosition(mUrl, mObjects); } } else { mChangeVolume = true; mGestureDownVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { JC_BURIED_POINT.onTouchScreenSeekVolume(mUrl, mObjects); } } @@ -401,8 +389,8 @@ public boolean onTouch(View v, MotionEvent event) { mSeekTimePosition = (int) (mDownPosition + deltaX * totalTimeDuration / mScreenWidth); if (mSeekTimePosition > totalTimeDuration) mSeekTimePosition = totalTimeDuration; - String seekTime = Utils.stringForTime(mSeekTimePosition); - String totalTime = Utils.stringForTime(totalTimeDuration); + String seekTime = JCUtils.stringForTime(mSeekTimePosition); + String totalTime = JCUtils.stringForTime(totalTimeDuration); showProgressDialog(deltaX, seekTime, mSeekTimePosition, totalTime, totalTimeDuration); } @@ -430,7 +418,7 @@ public boolean onTouch(View v, MotionEvent event) { } ///////////////////// startProgressTimer(); - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { if (mIfCurrentIsFullscreen) { JC_BURIED_POINT.onClickSeekbarFullscreen(mUrl, mObjects); } else { @@ -508,6 +496,10 @@ public void onStopTrackingTouch(SeekBar seekBar) { public void onPrepared() { if (mCurrentState != CURRENT_STATE_PREPAREING) return; JCMediaManager.instance().mediaPlayer.start(); + if (seekToInAdvance != -1) { + JCMediaManager.instance().mediaPlayer.seekTo(seekToInAdvance); + seekToInAdvance = -1; + } startProgressTimer(); setStateAndUi(CURRENT_STATE_PLAYING); } @@ -515,7 +507,7 @@ public void onPrepared() { @Override public void onAutoCompletion() { //make me normal first - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { if (mIfCurrentIsFullscreen) { JC_BURIED_POINT.onAutoCompleteFullscreen(mUrl, mObjects); } else { @@ -529,9 +521,9 @@ public void onAutoCompletion() { finishFullscreenActivity(); if (IF_FULLSCREEN_FROM_NORMAL) {//如果在进入全屏后播放完就初始化自己非全屏的控件 IF_FULLSCREEN_FROM_NORMAL = false; - JCMediaManager.instance().lastListener.onAutoCompletion(); + JCMediaManager.instance().lastListener().onAutoCompletion(); } - JCMediaManager.instance().lastListener = null; + JCMediaManager.instance().setLastListener(null); AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); mAudioManager.abandonAudioFocus(onAudioFocusChangeListener); ((Activity) getContext()).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); @@ -549,10 +541,10 @@ public void onCompletion() { if (IF_FULLSCREEN_FROM_NORMAL) {//如果在进入全屏后播放完就初始化自己非全屏的控件 IF_FULLSCREEN_FROM_NORMAL = false; - JCMediaManager.instance().lastListener.onCompletion(); + JCMediaManager.instance().lastListener().onCompletion(); } - JCMediaManager.instance().listener = null; - JCMediaManager.instance().lastListener = null; + JCMediaManager.instance().setListener(null); + JCMediaManager.instance().setLastListener(null); JCMediaManager.instance().currentVideoWidth = 0; JCMediaManager.instance().currentVideoHeight = 0; @@ -652,7 +644,7 @@ protected int getCurrentPositionWhenPlaying() { int position = 0; if (mCurrentState == CURRENT_STATE_PLAYING || mCurrentState == CURRENT_STATE_PAUSE) { try { - position = JCMediaManager.instance().mediaPlayer.getCurrentPosition(); + position = (int) JCMediaManager.instance().mediaPlayer.getCurrentPosition(); } catch (IllegalStateException e) { e.printStackTrace(); return position; @@ -664,7 +656,7 @@ protected int getCurrentPositionWhenPlaying() { protected int getDuration() { int duration = 0; try { - duration = JCMediaManager.instance().mediaPlayer.getDuration(); + duration = (int) JCMediaManager.instance().mediaPlayer.getDuration(); } catch (IllegalStateException e) { e.printStackTrace(); return duration; @@ -684,28 +676,29 @@ protected void setProgressAndTime(int progress, int secProgress, int currentTime if (!mTouchingProgressBar) { if (progress != 0) progressBar.setProgress(progress); } + if (secProgress > 95) secProgress = 100; if (secProgress != 0) progressBar.setSecondaryProgress(secProgress); - currentTimeTextView.setText(Utils.stringForTime(currentTime)); - totalTimeTextView.setText(Utils.stringForTime(totalTime)); + currentTimeTextView.setText(JCUtils.stringForTime(currentTime)); + totalTimeTextView.setText(JCUtils.stringForTime(totalTime)); } protected void resetProgressAndTime() { progressBar.setProgress(0); progressBar.setSecondaryProgress(0); - currentTimeTextView.setText(Utils.stringForTime(0)); - totalTimeTextView.setText(Utils.stringForTime(0)); + currentTimeTextView.setText(JCUtils.stringForTime(0)); + totalTimeTextView.setText(JCUtils.stringForTime(0)); } protected void quitFullScreenGoToNormal() { Log.d(TAG, "quitFullScreenGoToNormal [" + this.hashCode() + "] "); - if (JC_BURIED_POINT != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT != null && isCurrentMediaListener()) { JC_BURIED_POINT.onQuitFullscreen(mUrl, mObjects); } JCMediaManager.instance().setDisplay(null); - JCMediaManager.instance().listener = JCMediaManager.instance().lastListener; - JCMediaManager.instance().lastListener = null; + JCMediaManager.instance().setListener(JCMediaManager.instance().lastListener()); + JCMediaManager.instance().setLastListener(null); JCMediaManager.instance().lastState = mCurrentState;//save state - JCMediaManager.instance().listener.onBackFullscreen(); + JCMediaManager.instance().listener().onBackFullscreen(); if (mCurrentState == CURRENT_STATE_PAUSE) { JCMediaManager.instance().mediaPlayer.seekTo(JCMediaManager.instance().mediaPlayer.getCurrentPosition()); } @@ -723,7 +716,7 @@ public void backFullscreen() { Log.d(TAG, "quitFullscreen [" + this.hashCode() + "] "); IF_FULLSCREEN_FROM_NORMAL = false; if (mIfFullscreenIsDirectly) { - JCMediaManager.instance().mediaPlayer.stop(); + JCMediaManager.instance().mediaPlayer.release(); finishFullscreenActivity(); } else { CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis(); @@ -735,8 +728,8 @@ public void backFullscreen() { public static void releaseAllVideos() { if (IF_RELEASE_WHEN_ON_PAUSE) { Log.d(TAG, "releaseAllVideos"); - if (JCMediaManager.instance().listener != null) { - JCMediaManager.instance().listener.onCompletion(); + if (JCMediaManager.instance().listener() != null) { + JCMediaManager.instance().listener().onCompletion(); } JCMediaManager.instance().releaseMediaPlayer(); } else { @@ -748,12 +741,15 @@ public static void releaseAllVideos() { * if I am playing release me */ public void release() { - if (JCMediaManager.instance().listener == this && -// mCurrentState != CURRENT_STATE_NORMAL && + if (isCurrentMediaListener() && (System.currentTimeMillis() - CLICK_QUIT_FULLSCREEN_TIME) > FULL_SCREEN_NORMAL_DELAY) { Log.d(TAG, "release [" + this.hashCode() + "]"); releaseAllVideos(); } } + protected boolean isCurrentMediaListener() { + return JCMediaManager.instance().listener() != null + && JCMediaManager.instance().listener() == this; + } } diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayerStandard.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayerStandard.java index af1ccdeb3..668a436cc 100644 --- a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayerStandard.java +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayerStandard.java @@ -158,24 +158,8 @@ public void onClick(View v) { return; } if (mCurrentState == CURRENT_STATE_NORMAL) { - if (!Utils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setMessage(getResources().getString(R.string.tips_not_wifi)); - builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - startPlayLocic(); - WIFI_TIP_DIALOG_SHOWED = true; - } - }); - builder.setNegativeButton(getResources().getString(R.string.tips_not_wifi_cancel), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - builder.create().show(); + if (!mUrl.startsWith("file") && !JCUtils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) { + showWifiDialog(); return; } startPlayLocic(); @@ -183,7 +167,7 @@ public void onClick(DialogInterface dialog, int which) { onClickUiToggle(); } } else if (i == R.id.surface_container) { - if (JC_BURIED_POINT_STANDARD != null && JCMediaManager.instance().listener == this) { + if (JC_BURIED_POINT_STANDARD != null && isCurrentMediaListener()) { if (mIfCurrentIsFullscreen) { JC_BURIED_POINT_STANDARD.onClickBlankFullscreen(mUrl, mObjects); } else { @@ -196,6 +180,28 @@ public void onClick(DialogInterface dialog, int which) { } } + @Override + public void showWifiDialog() { + super.showWifiDialog(); + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setMessage(getResources().getString(R.string.tips_not_wifi)); + builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + startPlayLocic(); + WIFI_TIP_DIALOG_SHOWED = true; + } + }); + builder.setNegativeButton(getResources().getString(R.string.tips_not_wifi_cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.create().show(); + } + private void startPlayLocic() { if (JC_BURIED_POINT_STANDARD != null) { JC_BURIED_POINT_STANDARD.onClickStartThumb(mUrl, mObjects);