[Android] Refine slaves management on media loading

Geoffrey Métais git at videolan.org
Wed May 2 18:54:12 CEST 2018


vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May  2 18:52:30 2018 +0200| [68f2cbb3b4f655ad46dd111303d26d150904dd02] | committer: Geoffrey Métais

Refine slaves management on media loading

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

 vlc-android/src/org/videolan/vlc/media/PlayerController.kt | 10 ++++++++--
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt  |  6 +-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index e95272087..123c50c9c 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -180,8 +180,14 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
         setPlaybackStopped()
     }
 
-    fun setSlaves(media: MediaWrapper) = launch {
-        val list = MediaDatabase.getInstance().getSlaves(media.location)
+    suspend fun setSlaves(media: Media, mw: MediaWrapper) {
+        val list = withContext(CommonPool) {
+            mw.slaves?.let {
+                for (slave in it) media.addSlave(slave)
+                MediaDatabase.getInstance().saveSlaves(mw)
+            }
+            MediaDatabase.getInstance().getSlaves(mw.location)
+        }
         for (slave in list) mediaplayer.addSlave(slave.type, Uri.parse(slave.uri), false)
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 2d238ea86..5fa154605 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -263,12 +263,8 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                         isHardware = false
                     }
                 }
-                mw.slaves?.let {
-                    for (slave in it) media.addSlave(slave)
-                    launch { MediaDatabase.getInstance().saveSlaves(mw) }
-                }
                 media.setEventListener(this at PlaylistManager)
-                player.setSlaves(mw)
+                player.setSlaves(media, mw)
                 player.startPlayback(media, mediaplayerEventListener)
                 media.release()
                 if (savedTime <= 0L && mw.time >= 0L && mw.isPodcast) savedTime = mw.time



More information about the Android mailing list