[Android] Handle video chaining in background with restore

Geoffrey Métais git at videolan.org
Tue Apr 5 18:55:06 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr  5 18:50:59 2016 +0200| [72ab953e886d07a49d2d99ac729477b2454845f1] | committer: Geoffrey Métais

Handle video chaining in background with restore

> https://code.videolan.org/videolan/vlc-android/commit/72ab953e886d07a49d2d99ac729477b2454845f1
---

 vlc-android/src/org/videolan/vlc/PlaybackService.java | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index de11f19..67ff3e5 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -140,6 +140,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     private boolean mIsAudioTrack = false;
     private boolean mHasHdmiAudio = false;
     private boolean mSwitchingToVideo = false;
+    private boolean mVideoBackground = false;
 
     final private ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
     private boolean mDetectHeadset = true;
@@ -620,10 +621,11 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                     changeAudioFocus(true);
                     if (!mWakeLock.isHeld())
                         mWakeLock.acquire();
-                    if (switchToVideo())
+                    if (!mVideoBackground && switchToVideo())
                         hideNotification();
                     else
                         showNotification();
+                    mVideoBackground = false;
                     break;
                 case MediaPlayer.Event.Paused:
                     Log.i(TAG, "MediaPlayer.Event.Paused");
@@ -670,7 +672,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
                 case MediaPlayer.Event.Vout:
                     break;
                 case MediaPlayer.Event.ESAdded:
-                    if (event.getEsChangedType() == Media.Track.Type.Video && !switchToVideo()) {
+                    if (event.getEsChangedType() == Media.Track.Type.Video && (mVideoBackground || !switchToVideo())) {
                         /* Update notification content intent: resume video or resume audio activity */
                         updateMetadata();
                     }
@@ -753,6 +755,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
     public boolean switchToVideo() {
         if (mMediaList.getMedia(mCurrentIndex).hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) || !canSwitchToVideo())
             return false;
+        mVideoBackground = false;
         if (isVideoPlaying()) {//Player is already running, just send it an intent
             setVideoTrackEnabled(true);
             LocalBroadcastManager.getInstance(this).sendBroadcast(
@@ -871,7 +874,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
 
 
             PendingIntent pendingIntent;
-            if (canSwitchToVideo() && !mMediaList.getMedia(mCurrentIndex).hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) ) {
+            if (mVideoBackground || (canSwitchToVideo() && !mMediaList.getMedia(mCurrentIndex).hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO))) {
                 /* Resume VideoPlayerActivity from ACTION_REMOTE_SWITCH_VIDEO intent */
                 final Intent notificationIntent = new Intent(ACTION_REMOTE_SWITCH_VIDEO);
                 pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
@@ -1210,6 +1213,7 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
             stop();
             return;
         }
+        mVideoBackground = !isVideoPlaying() && canSwitchToVideo();
         playIndex(mCurrentIndex, 0);
         saveCurrentMedia();
     }
@@ -1681,9 +1685,12 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         final MediaWrapper mw = mMediaList.getMedia(index);
         if (mw == null)
             return;
-        if (mw.getType() == MediaWrapper.TYPE_VIDEO && isVideoPlaying())
+        if (!mVideoBackground && mw.getType() == MediaWrapper.TYPE_VIDEO && isVideoPlaying())
             mw.addFlags(MediaWrapper.MEDIA_VIDEO);
 
+        if (mVideoBackground)
+            mw.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
+
         /* Pausable and seekable are true by default */
         mParsed = false;
         mSwitchingToVideo = false;
@@ -1694,7 +1701,9 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
         if (mMediaPlayer.getMedia() == null || !mw.getUri().equals(mMediaPlayer.getMedia().getUri()))
             mMediaPlayer.setMedia(media);
         media.release();
-        if (mw .getType() != MediaWrapper.TYPE_VIDEO || mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) || isVideoPlaying()) {
+
+        if (mw .getType() != MediaWrapper.TYPE_VIDEO || mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO)
+                || isVideoPlaying()) {
             mMediaPlayer.setEqualizer(VLCOptions.getEqualizer(this));
             mMediaPlayer.setVideoTitleDisplay(MediaPlayer.Position.Disable, 0);
             changeAudioFocus(true);



More information about the Android mailing list