[Android] Safer media & player releasing order

Geoffrey Métais git at videolan.org
Mon May 7 15:36:02 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May  7 15:18:54 2018 +0200| [8a0b6dde337f24db20bdad81b9804f8015d5fbb9] | committer: Geoffrey Métais

Safer media & player releasing order

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

 vlc-android/src/org/videolan/vlc/media/PlayerController.kt | 3 ++-
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt  | 3 +--
 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 858aa9820..273837561 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -60,7 +60,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
         setPlaybackStopped()
     }
 
-    fun releaseMedia() = mediaplayer.media?.let {
+    private fun releaseMedia() = mediaplayer.media?.let {
         it.setEventListener(null)
         it.release()
     }
@@ -172,6 +172,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
     fun release(player: MediaPlayer = mediaplayer) {
         player.setEventListener(null)
         if (isVideoPlaying()) player.vlcVout.detachViews()
+        releaseMedia()
         launch(newSingleThreadContext("vlc-player-release")) {
             if (BuildConfig.DEBUG) { // Warn if player release is blocking
                 try {
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 4458f8ff3..8bda43253 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -194,13 +194,12 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             savePosition()
             saveMediaMeta()
         }
-        player.releaseMedia()
         mediaList.removeEventListener(this)
         previous.clear()
         currentIndex = -1
-        mediaList.clear()
         if (systemExit) player.release()
         else player.restart()
+        mediaList.clear()
         showAudioPlayer.value = false
         service.onPlaybackStopped(systemExit)
     }



More information about the Android mailing list