Commit fd841ff5 authored by Geoffrey Métais's avatar Geoffrey Métais

Add video tracks selector in video player

(cherry picked from commit c32f99fa)
parent e94cc5a3
<?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" />
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment