Commit 48f7a596 authored by Geoffrey Métais's avatar Geoffrey Métais

Browser: retain/release media

parent ad406c79
......@@ -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 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment