[Android] VideoPlayer: use "start-paused" option
Thomas Guillem
git at videolan.org
Wed Mar 25 15:56:49 CET 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Mar 23 14:51:16 2015 +0100| [5d040b9618d466c2146ee7a3f0904832753a4cb4] | committer: Thomas Guillem
VideoPlayer: use "start-paused" option
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=5d040b9618d466c2146ee7a3f0904832753a4cb4
---
.../org/videolan/vlc/MediaWrapperListPlayer.java | 11 +++--
.../vlc/gui/video/VideoPlayerActivity.java | 46 ++++++++------------
2 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java b/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java
index e8a70b7..562be13 100644
--- a/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/MediaWrapperListPlayer.java
@@ -53,18 +53,23 @@ public class MediaWrapperListPlayer {
* Play a media from the media list (playlist)
*
* @param position The index of the media
+ * @param paused start the media paused
*/
- public void playIndex(int position) {
+ public void playIndex(int position, boolean paused) {
String mrl = mMediaList.getMRL(position);
if (mrl == null)
return;
-
+ final int pausedFlag = paused ? LibVLC.MEDIA_PAUSED : 0;
final MediaWrapper media = mMediaList.getMedia(position);
- String[] options = mLibVLC.getMediaOptions(media != null ? media.getFlags() : 0);
+ String[] options = mLibVLC.getMediaOptions(pausedFlag | (media != null ? media.getFlags() : 0));
mPlayerIndex = position;
mLibVLC.playMRL(mrl, options);
}
+ public void playIndex(int position) {
+ playIndex(position, false);
+ }
+
/**
* Expand and continue playing the current media.
*
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 9dfbb35..4353695 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -274,7 +274,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
* Flag to indicate whether the media should be paused once loaded
* (e.g. lock screen, or to restore the pause state)
*/
- private boolean mPauseOnLoaded = false;
private boolean mPlaybackStarted = false;
/**
@@ -600,7 +599,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
protected void onResume() {
super.onResume();
mSwitchingView = false;
- mPauseOnLoaded = false;
bindAudioService();
@@ -643,17 +641,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
}
setSurfaceLayout(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
- /*
- * If the activity has been paused by pressing the power button, then
- * pressing it again will show the lock screen.
- * But onResume will also be called, even if vlc-android is still in
- * the background.
- * To workaround this, pause playback if the lockscreen is displayed.
- */
- KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
- if(km.inKeyguardRestrictedInputMode())
- mPauseOnLoaded = true;
-
if (mMediaRouter != null) {
// Listen for changes to media routes.
mediaRouterAddCallback(true);
@@ -1356,12 +1343,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
break;
case EventHandler.MediaPlayerPlaying:
Log.i(TAG, "MediaPlayerPlaying");
- // Handle pause flag
- if(activity.mPauseOnLoaded) {
- activity.mPauseOnLoaded = false;
- activity.mLibVLC.pause();
- activity.setOverlayProgress();
- }
activity.stopLoadingAnimation();
activity.showOverlay();
activity.setESTracks();
@@ -2491,6 +2472,22 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
String itemTitle = null;
long intentPosition = -1; // position passed in by intent (ms)
+ boolean wasPaused;
+ /*
+ * If the activity has been paused by pressing the power button, then
+ * pressing it again will show the lock screen.
+ * But onResume will also be called, even if vlc-android is still in
+ * the background.
+ * To workaround this, pause playback if the lockscreen is displayed.
+ */
+ final KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
+ if (km.inKeyguardRestrictedInputMode())
+ wasPaused = true;
+ else
+ wasPaused = mSettings.getBoolean(PreferencesActivity.VIDEO_PAUSED, false);
+ if (wasPaused)
+ Log.d(TAG, "Video was previously paused, resuming in paused mode");
+
if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_VIEW)) {
/* Started from external application 'content' */
@@ -2607,7 +2604,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
/* Start / resume playback */
if (savedIndexPosition > -1) {
AudioServiceController.getInstance().stop(); // Stop the previous playback.
- mMediaListPlayer.playIndex(savedIndexPosition);
+ mMediaListPlayer.playIndex(savedIndexPosition, wasPaused);
} else if (mLocation != null && mLocation.length() > 0) {
AudioServiceController.getInstance().stop(); // Stop the previous playback.
mMediaListPlayer.getMediaList().clear();
@@ -2616,7 +2613,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
media.release();
mMediaListPlayer.getMediaList().add(new MediaWrapper(media));
savedIndexPosition = mMediaListPlayer.getMediaList().size() - 1;
- mMediaListPlayer.playIndex(savedIndexPosition);
+ mMediaListPlayer.playIndex(savedIndexPosition, wasPaused);
}
mCanSeek = false;
@@ -2646,13 +2643,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
seek(intentPosition);
}
- // Paused flag
- boolean wasPaused = mSettings.getBoolean(PreferencesActivity.VIDEO_PAUSED, false);
- if(wasPaused) {
- Log.d(TAG, "Video was previously paused, resuming in paused mode");
- mPauseOnLoaded = true;
- }
-
// Get possible subtitles
String subtitleList_serialized = mSettings.getString(PreferencesActivity.VIDEO_SUBTITLE_FILES, null);
ArrayList<String> prefsList = new ArrayList<String>();
More information about the Android
mailing list