[Android] Browser: retain/release media

Geoffrey Métais git at videolan.org
Mon Oct 15 11:18:38 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Oct 15 11:18:02 2018 +0200| [48f7a59627e9f22c2715c6f605800b65bb2e9594] | committer: Geoffrey Métais

Browser: retain/release media

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

 vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index 88c4d628e..7c616de63 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -175,7 +175,12 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
         }
     }
 
-    override fun onMediaAdded(index: Int, media: Media) { if (!browserChannel.isClosedForReceive) browserChannel.offer(media) }
+    override fun onMediaAdded(index: Int, media: Media) {
+        if (!browserChannel.isClosedForReceive) {
+            media.retain()
+            browserChannel.offer(media)
+        }
+    }
     override fun onBrowseEnd() { browserChannel.close() }
     override fun onMediaRemoved(index: Int, media: Media){}
 
@@ -194,6 +199,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
 
     private suspend fun findMedia(media: Media): MediaWrapper {
         val mw = MediaWrapper(media)
+        media.release()
         val uri = mw.uri
         if ((mw.type == MediaWrapper.TYPE_AUDIO || mw.type == MediaWrapper.TYPE_VIDEO)
                 && "file" == uri.scheme) return withContext(Dispatchers.IO) { medialibrary.getMedia(uri) ?: mw }



More information about the Android mailing list