[Android] Save spu or audio tracks on change

Geoffrey Métais git at videolan.org
Wed Oct 17 10:28:35 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Oct 17 10:27:07 2018 +0200| [32409efe07a3527f7302d7c1e9755dd4552b854b] | committer: Geoffrey Métais

Save spu or audio tracks on change

Remove the old systematic meta saving. It could deactivate subs

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

 .../src/org/videolan/vlc/PlaybackService.kt        |  6 +++---
 .../src/org/videolan/vlc/media/PlaylistManager.kt  | 25 ++++++++++++++++------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index eed50ce3e..5c362b104 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1165,13 +1165,13 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope {
     fun addSubtitleTrack(uri: Uri, select: Boolean) = playlistManager.player.addSubtitleTrack(uri, select)
 
     @MainThread
-    fun setSpuTrack(index: Int) = playlistManager.player.setSpuTrack(index)
+    fun setSpuTrack(index: Int) = playlistManager.setSpuTrack(index)
 
     @MainThread
-    fun setAudioDelay(delay: Long) = playlistManager.player.setAudioDelay(delay)
+    fun setAudioDelay(delay: Long) = playlistManager.setAudioDelay(delay)
 
     @MainThread
-    fun setSpuDelay(delay: Long) = playlistManager.player.setSpuDelay(delay)
+    fun setSpuDelay(delay: Long) = playlistManager.setSpuDelay(delay)
 
     @MainThread
     fun hasRenderer() = playlistManager.player.hasRenderer
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 0d77bd045..031d131be 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -415,15 +415,28 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             media.time = if (progress == 0f) 0L else time
             media.setLongMeta(MediaWrapper.META_PROGRESS, media.time)
         }
-        if (canSwitchToVideo) {
-            //Save audio delay
-            if (settings.getBoolean("save_individual_audio_delay", false))
-                media.setLongMeta(MediaWrapper.META_AUDIODELAY, player.getAudioDelay())
-            media.setLongMeta(MediaWrapper.META_SUBTITLE_DELAY, player.getSpuDelay())
-            media.setLongMeta(MediaWrapper.META_SUBTITLE_TRACK, player.getSpuTrack().toLong())
+    }
+
+    fun setSpuTrack(index: Int) {
+        if (!player.setSpuTrack(index)) return
+        val media = getCurrentMedia() ?: return
+        if (media.id != 0L) launch(Dispatchers.IO) { media.setLongMeta(MediaWrapper.META_SUBTITLE_TRACK, player.getSpuTrack().toLong()) }
+    }
+
+    fun setAudioDelay(delay: Long) {
+        if (!player.setAudioDelay(delay)) return
+        val media = getCurrentMedia() ?: return
+        if (media.id != 0L && settings.getBoolean("save_individual_audio_delay", false)) {
+            launch(Dispatchers.IO) { media.setLongMeta(MediaWrapper.META_AUDIODELAY, player.getAudioDelay()) }
         }
     }
 
+    fun setSpuDelay(delay: Long) {
+        if (!player.setSpuDelay(delay)) return
+        val media = getCurrentMedia() ?: return
+        if (media.id != 0L) launch(Dispatchers.IO) { media.setLongMeta(MediaWrapper.META_SUBTITLE_DELAY, player.getSpuDelay()) }
+    }
+
     private fun loadMediaMeta(media: MediaWrapper) {
         if (media.id == 0L) return
         if (player.canSwitchToVideo()) {



More information about the Android mailing list