[Android] Fix dispatch during Mediaplayer.setMedia()

Geoffrey Métais git at videolan.org
Tue Jan 29 09:43:54 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan 28 17:48:38 2019 +0100| [08375f29c57b58e6c1b71eae5e626df601f4b345] | committer: Geoffrey Métais

Fix dispatch during Mediaplayer.setMedia()

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

 vlc-android/src/org/videolan/vlc/media/PlayerController.kt | 4 ++--
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index 08bf089e3..bf6ef2917 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -73,11 +73,11 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
     }
 
     private var mediaplayerEventListener: MediaPlayerEventListener? = null
-    internal fun startPlayback(media: Media, listener: MediaPlayerEventListener) {
+    internal suspend fun startPlayback(media: Media, listener: MediaPlayerEventListener) {
         mediaplayerEventListener = listener
         resetPlaybackState(media.duration)
         mediaplayer.setEventListener(null)
-        mediaplayer.media = media.apply { if (hasRenderer) parse() }
+        withContext(Dispatchers.IO) { mediaplayer.media = media.apply { if (hasRenderer) parse() } }
         mediaplayer.setEventListener(this at PlayerController)
         mediaplayer.setEqualizer(VLCOptions.getEqualizerSetFromSettings(context))
         mediaplayer.setVideoTitleDisplay(MediaPlayer.Position.Disable, 0)
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index cafe76396..6e3551108 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -307,7 +307,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 }
             }
             media.setEventListener(this at PlaylistManager)
-            withContext(Dispatchers.Main) { player.startPlayback(media, mediaplayerEventListener) }
+            player.startPlayback(media, mediaplayerEventListener)
             player.setSlaves(media, mw)
             newMedia = true
             determinePrevAndNextIndices()



More information about the Android mailing list