[Android] Playback: Check if mediaplayer is released

Geoffrey Métais git at videolan.org
Tue Feb 26 14:13:57 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 26 12:53:18 2019 +0100| [25e85c0fc849cf847de80030baaa2fc00fac4643] | committer: Geoffrey Métais

Playback: Check if mediaplayer is released

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

 vlc-android/src/org/videolan/vlc/media/PlayerController.kt | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index 04f7f1c04..d1dd484dd 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -77,11 +77,13 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
         mediaplayerEventListener = listener
         resetPlaybackState(media.duration)
         mediaplayer.setEventListener(null)
-        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)
-        mediaplayer.play()
+        withContext(Dispatchers.IO) { if (!mediaplayer.isReleased) mediaplayer.media = media.apply { if (hasRenderer) parse() } }
+        if (!mediaplayer.isReleased) {
+            mediaplayer.setEventListener(this at PlayerController)
+            mediaplayer.setEqualizer(VLCOptions.getEqualizerSetFromSettings(context))
+            mediaplayer.setVideoTitleDisplay(MediaPlayer.Position.Disable, 0)
+            mediaplayer.play()
+        }
     }
 
     private fun resetPlaybackState(duration: Long) {
@@ -194,6 +196,7 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
     }
 
     fun setSlaves(media: Media, mw: MediaWrapper) = launch {
+        if (mediaplayer.isReleased) return at launch
         val slaves = mw.slaves
         slaves?.let { it.forEach { slave -> media.addSlave(slave) } }
         media.release()



More information about the Android mailing list