[Android] Refine slaves management on media loading

Geoffrey Métais git at videolan.org
Thu May 3 14:17:11 CEST 2018


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

Refine slaves management on media loading

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

 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 b67fac449..058d7aa23 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -182,8 +182,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 2687bb042..5550acd32 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -270,12 +270,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()
                 determinePrevAndNextIndices()



More information about the Android mailing list