[Android] [PATCH 2/2] VideoPlayer: update audio and subtitles tracks during playback

Thomas Guillem thomas at gllm.fr
Wed Mar 18 18:58:18 CET 2015


We now fetch audio and subtitles tracks only before we show the dialog and if
they have been invalidated (due to a ES change).

Fixes #7540
---
 .../vlc/gui/video/VideoPlayerActivity.java         | 40 ++++++++++++----------
 1 file changed, 22 insertions(+), 18 deletions(-)

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 989f1b6..ae4a8fa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1337,9 +1337,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
                     }
                     activity.stopLoadingAnimation();
                     activity.showOverlay();
-                    /** FIXME: update the track list when it changes during the
-                     *  playback. (#7540) */
-                    activity.setESTrackLists(true);
                     activity.setESTracks();
                     activity.changeAudioFocus(true);
                     activity.updateNavStatus();
@@ -1382,6 +1379,9 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
                         Log.i(TAG, "No video track, open in audio mode");
                         activity.switchToAudioMode();
                     }
+                    // no break here, we want to invalidate tracks
+                case EventHandler.MediaPlayerESDeleted:
+                    activity.invalidateESTracks(msg.getData().getInt("data"));
                     break;
                 default:
                     break;
@@ -2003,7 +2003,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
     }
 
     private void selectAudioTrack() {
-        setESTrackLists(false);
+        setESTrackLists();
         selectTrack(mAudioTracksList, mLibVLC.getAudioTrack(), R.string.track_audio,
                 new TrackSelectedListener() {
                     @Override
@@ -2021,7 +2021,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
     }
 
     private void selectSubtitles() {
-        setESTrackLists(false);
+        setESTrackLists();
         selectTrack(mSubtitleTracksList, mLibVLC.getSpuTrack(), R.string.track_text,
                 new TrackSelectedListener() {
                     @Override
@@ -2395,6 +2395,17 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         return time;
     }
 
+    private void invalidateESTracks(int type) {
+        switch (type) {
+            case Media.Track.Type.Audio:
+                mAudioTracksList = null;
+                break;
+            case Media.Track.Type.Text:
+                mSubtitleTracksList = null;
+                break;
+        }
+    }
+
     private void setESTracks() {
         if (mLastAudioTrack >= 0) {
             mLibVLC.setAudioTrack(mLastAudioTrack);
@@ -2406,16 +2417,11 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         }
     }
 
-    private void setESTrackLists(boolean force) {
-        if(mAudioTracksList == null || force) {
-            if (mLibVLC.getAudioTracksCount() > 2) {
-                mAudioTracksList = mLibVLC.getAudioTrackDescription();
-            }
-        }
-        if (mSubtitleTracksList == null || force) {
-            if (mLibVLC.getSpuTracksCount() > 0)
-                mSubtitleTracksList = mLibVLC.getSpuTrackDescription();
-        }
+    private void setESTrackLists() {
+        if(mAudioTracksList == null && mLibVLC.getAudioTracksCount() > 1)
+            mAudioTracksList = mLibVLC.getAudioTrackDescription();
+        if (mSubtitleTracksList == null && mLibVLC.getSpuTracksCount() > 0)
+            mSubtitleTracksList = mLibVLC.getSpuTrackDescription();
     }
 
 
@@ -2894,10 +2900,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
              */
             hideOverlay(false);
         }
-        else if (mHasMenu) {
-            setESTrackLists(true);
+        else if (mHasMenu)
             setESTracks();
-        }
         supportInvalidateOptionsMenu();
     }
 
-- 
2.1.3



More information about the Android mailing list