Loading core/java/android/widget/VideoView.java +72 −2 Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ public class VideoView extends SurfaceView private static final int STATE_PLAYING = 3; private static final int STATE_PAUSED = 4; private static final int STATE_PLAYBACK_COMPLETED = 5; private static final int STATE_SUSPENDED = 6; // mCurrentState is a VideoView object's current state. // mTargetState is the state that a method caller intends to reach. Loading Loading @@ -382,6 +383,22 @@ public class VideoView extends SurfaceView } } private boolean isHTTPStreaming(Uri mUri) { if (mUri != null) { String scheme = mUri.toString(); if (scheme.startsWith("http://") || scheme.startsWith("http://")) { if (scheme.endsWith(".m3u8") || scheme.endsWith(".m3u") || scheme.contains("m3u8") || scheme.endsWith(".mpd")) { // HLS or DASH streaming source return false; } // HTTP progressive download streaming source return true; } } return false; } MediaPlayer.OnVideoSizeChangedListener mSizeChangedListener = new MediaPlayer.OnVideoSizeChangedListener() { public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { Loading Loading @@ -604,6 +621,23 @@ public class VideoView extends SurfaceView public void surfaceCreated(SurfaceHolder holder) { mSurfaceHolder = holder; // if current state is suspended, call resume() to init the decoders again if (mCurrentState == STATE_SUSPENDED && mMediaPlayer != null) { mMediaPlayer.setDisplay(mSurfaceHolder); if (mMediaPlayer.resume()) { mCurrentState = STATE_PREPARED; if (mSeekWhenPrepared != 0) { // seek if necessary seekTo(mSeekWhenPrepared); } if (mTargetState == STATE_PLAYING) { start(); } return; } else { release(false); } } openVideo(); } Loading @@ -611,7 +645,12 @@ public class VideoView extends SurfaceView { // after we return from this we can't use the surface any more mSurfaceHolder = null; if (mMediaController != null) mMediaController.hide(); if (mMediaController != null) mMediaController.hide(); if (isHTTPStreaming(mUri) && mCurrentState == STATE_SUSPENDED) { // don't call release() while run suspend operation for http streaming source return; } release(true); } }; Loading Loading @@ -719,10 +758,40 @@ public class VideoView extends SurfaceView } public void suspend() { // HTTP streaming will call MediaPlayer::suspend() for suspend operation, others will call release() if (isHTTPStreaming(mUri) && mCurrentState > STATE_PREPARING && mMediaPlayer != null) { if (mMediaPlayer.suspend()) { mTargetState = mCurrentState; mCurrentState = STATE_SUSPENDED; return; } } release(false); } public void resume() { // HTTP streaming (with suspended status) will call MediaPlayer::resume(), others will call openVideo() if (mCurrentState == STATE_SUSPENDED && mMediaPlayer != null) { if (mSurfaceHolder != null) { if (mMediaPlayer.resume()) { mCurrentState = STATE_PREPARED; if (mSeekWhenPrepared != 0) { // seek if necessary seekTo(mSeekWhenPrepared); } if (mTargetState == STATE_PLAYING) { start(); } return; } else { // resume failed, so call release() before openVideo() release(false); } } else { // the surface has been destroyed, resume() will be called after surface created return; } } openVideo(); } Loading Loading @@ -770,7 +839,8 @@ public class VideoView extends SurfaceView return (mMediaPlayer != null && mCurrentState != STATE_ERROR && mCurrentState != STATE_IDLE && mCurrentState != STATE_PREPARING); mCurrentState != STATE_PREPARING && mCurrentState != STATE_SUSPENDED); } @Override Loading Loading
core/java/android/widget/VideoView.java +72 −2 Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ public class VideoView extends SurfaceView private static final int STATE_PLAYING = 3; private static final int STATE_PAUSED = 4; private static final int STATE_PLAYBACK_COMPLETED = 5; private static final int STATE_SUSPENDED = 6; // mCurrentState is a VideoView object's current state. // mTargetState is the state that a method caller intends to reach. Loading Loading @@ -382,6 +383,22 @@ public class VideoView extends SurfaceView } } private boolean isHTTPStreaming(Uri mUri) { if (mUri != null) { String scheme = mUri.toString(); if (scheme.startsWith("http://") || scheme.startsWith("http://")) { if (scheme.endsWith(".m3u8") || scheme.endsWith(".m3u") || scheme.contains("m3u8") || scheme.endsWith(".mpd")) { // HLS or DASH streaming source return false; } // HTTP progressive download streaming source return true; } } return false; } MediaPlayer.OnVideoSizeChangedListener mSizeChangedListener = new MediaPlayer.OnVideoSizeChangedListener() { public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { Loading Loading @@ -604,6 +621,23 @@ public class VideoView extends SurfaceView public void surfaceCreated(SurfaceHolder holder) { mSurfaceHolder = holder; // if current state is suspended, call resume() to init the decoders again if (mCurrentState == STATE_SUSPENDED && mMediaPlayer != null) { mMediaPlayer.setDisplay(mSurfaceHolder); if (mMediaPlayer.resume()) { mCurrentState = STATE_PREPARED; if (mSeekWhenPrepared != 0) { // seek if necessary seekTo(mSeekWhenPrepared); } if (mTargetState == STATE_PLAYING) { start(); } return; } else { release(false); } } openVideo(); } Loading @@ -611,7 +645,12 @@ public class VideoView extends SurfaceView { // after we return from this we can't use the surface any more mSurfaceHolder = null; if (mMediaController != null) mMediaController.hide(); if (mMediaController != null) mMediaController.hide(); if (isHTTPStreaming(mUri) && mCurrentState == STATE_SUSPENDED) { // don't call release() while run suspend operation for http streaming source return; } release(true); } }; Loading Loading @@ -719,10 +758,40 @@ public class VideoView extends SurfaceView } public void suspend() { // HTTP streaming will call MediaPlayer::suspend() for suspend operation, others will call release() if (isHTTPStreaming(mUri) && mCurrentState > STATE_PREPARING && mMediaPlayer != null) { if (mMediaPlayer.suspend()) { mTargetState = mCurrentState; mCurrentState = STATE_SUSPENDED; return; } } release(false); } public void resume() { // HTTP streaming (with suspended status) will call MediaPlayer::resume(), others will call openVideo() if (mCurrentState == STATE_SUSPENDED && mMediaPlayer != null) { if (mSurfaceHolder != null) { if (mMediaPlayer.resume()) { mCurrentState = STATE_PREPARED; if (mSeekWhenPrepared != 0) { // seek if necessary seekTo(mSeekWhenPrepared); } if (mTargetState == STATE_PLAYING) { start(); } return; } else { // resume failed, so call release() before openVideo() release(false); } } else { // the surface has been destroyed, resume() will be called after surface created return; } } openVideo(); } Loading Loading @@ -770,7 +839,8 @@ public class VideoView extends SurfaceView return (mMediaPlayer != null && mCurrentState != STATE_ERROR && mCurrentState != STATE_IDLE && mCurrentState != STATE_PREPARING); mCurrentState != STATE_PREPARING && mCurrentState != STATE_SUSPENDED); } @Override Loading