[Android] Fix picked subs not saved

Geoffrey Métais git at videolan.org
Wed Feb 13 10:31:04 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 13 10:30:33 2019 +0100| [b7a859d4e82fb52e91dfa7a69c238ff34be86d72] | committer: Geoffrey Métais

Fix picked subs not saved

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

 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java   | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 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 3df607b85..c743c9851 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -119,7 +119,6 @@ import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.WorkersKt;
 import org.videolan.vlc.viewmodels.PlaylistModel;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -803,13 +802,16 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
         mActionBarView.setOnTouchListener(null);
     }
 
+    private boolean mAddNextTrack = false;
     @Override
     protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
         if(data == null) return;
 
         if(data.hasExtra(FilePickerFragmentKt.EXTRA_MRL)) {
-            mService.addSubtitleTrack(Uri.parse(data.getStringExtra(FilePickerFragmentKt.EXTRA_MRL)), true);
-            SlaveRepository.Companion.getInstance(this).saveSlave(mService.getCurrentMediaLocation(), Media.Slave.Type.Subtitle, 2, data.getStringExtra(FilePickerFragmentKt.EXTRA_MRL));
+            mService.addSubtitleTrack(Uri.parse(data.getStringExtra(FilePickerFragmentKt.EXTRA_MRL)), false);
+            final MediaWrapper mw = mService.getCurrentMediaWrapper();
+            if (mw != null) SlaveRepository.Companion.getInstance(this).saveSlave(mw.getLocation(), Media.Slave.Type.Subtitle, 2, data.getStringExtra(FilePickerFragmentKt.EXTRA_MRL));
+            mAddNextTrack = true;
         } else if (BuildConfig.DEBUG) Log.d(TAG, "Subtitle selection dialog was cancelled");
     }
 
@@ -1461,8 +1463,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
                             @Override
                             public void run() {
                                 int spuTrack = (int) media.getMetaLong(MediaWrapper.META_SUBTITLE_TRACK);
-                                if (spuTrack != 0 || mCurrentSpuTrack != -2)
+                                if (mAddNextTrack) {
+                                    final MediaPlayer.TrackDescription[] tracks = mService.getSpuTracks();
+                                    if (!Util.isArrayEmpty(tracks)) mService.setSpuTrack(tracks[tracks.length-1].id);
+                                    mAddNextTrack = false;
+                                } else if (spuTrack != 0 || mCurrentSpuTrack != -2) {
                                     mService.setSpuTrack(media.getId() == 0L ? mCurrentSpuTrack : spuTrack);
+                                }
                             }
                         });
                     }



More information about the Android mailing list