[Android] Add video tracks selector in video player

Geoffrey Métais git at videolan.org
Fri Mar 16 11:40:41 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 16 11:35:27 2018 +0100| [c32f99faf6d25ce373e988ae283ae204b7a59076] | committer: Geoffrey Métais

Add video tracks selector in video player

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

 vlc-android/res/menu/audiosub_tracks.xml           |  3 +++
 .../src/org/videolan/vlc/PlaybackService.java      |  5 +++++
 .../vlc/gui/video/VideoPlayerActivity.java         | 23 ++++++++++++++++++++--
 .../src/org/videolan/vlc/media/PlayerController.kt |  2 ++
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/vlc-android/res/menu/audiosub_tracks.xml b/vlc-android/res/menu/audiosub_tracks.xml
index 7838801c6..460ce0275 100644
--- a/vlc-android/res/menu/audiosub_tracks.xml
+++ b/vlc-android/res/menu/audiosub_tracks.xml
@@ -1,5 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:id="@+id/video_menu_video_track"
+        android:title="@string/track_video" />
     <item
         android:id="@+id/video_menu_audio_track"
         android:title="@string/track_audio" />
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index d9c4107ef..6aeee4ba3 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1726,6 +1726,11 @@ public class PlaybackService extends MediaBrowserServiceCompat{
         return playlistManager.getPlayer().setAudioTrack(index);
     }
 
+    @MainThread
+    public boolean setVideoTrack(int index) {
+        return playlistManager.getPlayer().setVideoTrack(index);
+    }
+
     @MainThread
     public int getVideoTracksCount() {
         return hasMedia() ? playlistManager.getPlayer().getVideoTracksCount() : 0;
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 9accd4a29..262c9ddcb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -311,6 +311,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
 
     // Tracks & Subtitles
     private MediaPlayer.TrackDescription[] mAudioTracksList;
+    private MediaPlayer.TrackDescription[] mVideoTracksList;
     private MediaPlayer.TrackDescription[] mSubtitleTracksList;
     /**
      * Used to store a selected subtitle; see onActivityResult.
@@ -2370,6 +2371,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         //FIXME network subs cannot be enabled & screen cast display is broken with picker
         menu.findItem(R.id.video_menu_subtitles_picker).setEnabled(mDisplayManager.isPrimary() && enableSubs);
         menu.findItem(R.id.video_menu_subtitles_download).setEnabled(enableSubs);
+        menu.findItem(R.id.video_menu_video_track).setVisible(mService.getVideoTracksCount() > 2);
         menu.findItem(R.id.video_menu_audio_track).setEnabled(mService.getAudioTracksCount() > 0);
         menu.findItem(R.id.video_menu_subtitles).setEnabled(mService.getSpuTracksCount() > 0);
         popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@@ -2378,6 +2380,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                 if (item.getItemId() == R.id.video_menu_audio_track) {
                     selectAudioTrack();
                     return true;
+                } else if (item.getItemId() == R.id.video_menu_video_track) {
+                    selectVideoTrack();
+                    return true;
                 } else if (item.getItemId() == R.id.video_menu_subtitles) {
                     selectSubtitles();
                     return true;
@@ -2584,14 +2589,26 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         }
     }
 
+    private void selectVideoTrack() {
+        setESTrackLists();
+        selectTrack(mVideoTracksList, mService.getVideoTrack(), R.string.track_video,
+                new TrackSelectedListener() {
+                    @Override
+                    public void onTrackSelected(int trackID) {
+                        if (trackID < -1 || mService == null) return;
+                        mService.setVideoTrack(trackID);
+                        seek(mService.getTime());
+                    }
+                });
+    }
+
     private void selectAudioTrack() {
         setESTrackLists();
         selectTrack(mAudioTracksList, mService.getAudioTrack(), R.string.track_audio,
                 new TrackSelectedListener() {
                     @Override
                     public void onTrackSelected(int trackID) {
-                        if (trackID < -1 || mService == null)
-                            return;
+                        if (trackID < -1 || mService == null) return;
                         mService.setAudioTrack(trackID);
                         MediaWrapper mw = mMedialibrary.findMedia(mService.getCurrentMediaWrapper());
                         if (mw != null && mw.getId() != 0L)
@@ -2986,6 +3003,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             mAudioTracksList = mService.getAudioTracks();
         if (mSubtitleTracksList == null && mService.getSpuTracksCount() > 0)
             mSubtitleTracksList = mService.getSpuTracks();
+        if (mVideoTracksList == null && mService.getVideoTracksCount() > 0)
+            mVideoTracksList = mService.getVideoTracks();
     }
 
 
diff --git a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index 119e0a093..a98a00a1b 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -119,6 +119,8 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
 
     fun getAudioTrack() = mediaplayer.audioTrack
 
+    fun setVideoTrack(index: Int) = mediaplayer.setVideoTrack(index)
+
     fun setAudioTrack(index: Int) = mediaplayer.setAudioTrack(index)
 
     fun getAudioDelay() = mediaplayer.audioDelay



More information about the Android mailing list