[Android] Save medialist before loading a new one
Geoffrey Métais
git at videolan.org
Thu Jan 24 14:08:49 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jan 24 14:07:56 2019 +0100| [1f4af6fe3a730867dbdf7ad5a5987533f62dc389] | committer: Geoffrey Métais
Save medialist before loading a new one
> https://code.videolan.org/videolan/vlc-android/commit/1f4af6fe3a730867dbdf7ad5a5987533f62dc389
---
.../src/org/videolan/vlc/media/PlaylistManager.kt | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 3625ba2d7..5db87ddfe 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -106,11 +106,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
@MainThread
fun load(list: List<MediaWrapper>, position: Int, mlUpdate: Boolean = false) {
- mediaList.removeEventListener(this)
- mediaList.clear()
- previous.clear()
- videoBackground = false
launch {
+ saveMediaList()
+ savePosition()
+ mediaList.removeEventListener(this at PlaylistManager)
+ mediaList.clear()
+ previous.clear()
+ videoBackground = false
withContext(Dispatchers.IO) { for (media in list) mediaList.add(medialibrary.findMedia(media)) }
if (!hasMedia()) {
Log.w(TAG, "Warning: empty media list, nothing to play !")
@@ -463,12 +465,11 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
.apply()
}
- @Synchronized
- private fun saveMediaList() {
+ private suspend fun saveMediaList() {
if (getCurrentMedia() === null) return
val locations = StringBuilder()
- launch(Dispatchers.Main) {
- val list = mediaList.all.takeIf { it.isNotEmpty() } ?: return at launch
+ withContext(Dispatchers.Default) {
+ val list = mediaList.all.takeIf { it.isNotEmpty() } ?: return at withContext
for (mw in list) locations.append(" ").append(Uri.encode(Uri.decode(mw.uri.toString())))
//We save a concatenated String because putStringSet is APIv11.
settings.edit()
More information about the Android
mailing list