[Android] Add a current media LiveData to the PlaylistManager

Nicolas Pomepuy git at videolan.org
Wed Oct 11 16:36:33 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Oct  9 14:51:00 2023 +0200| [63500ef4665bb54ebb6781ce4c8d025238095e16] | committer: Duncan McNamara

Add a current media LiveData to the PlaylistManager

> https://code.videolan.org/videolan/vlc-android/commit/63500ef4665bb54ebb6781ce4c8d025238095e16
---

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

diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 81f10b5555..09106870d2 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -47,6 +47,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
     companion object {
         val showAudioPlayer = MutableLiveData<Boolean>().apply { value = false }
+        val currentPlayedMedia = MutableLiveData<MediaWrapper?>().apply { value = null }
         // The playback will periodically modify the media by saving its meta
         // When playing audio, it will have no impact on UI but will trigger the media modified ML callback
         // On slow devices, it will trigger an unwanted "refresh animation". This flag prevents it
@@ -62,6 +63,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     private val settings by lazy(LazyThreadSafetyMode.NONE) { Settings.getInstance(service) }
     private val ctx by lazy(LazyThreadSafetyMode.NONE) { service.applicationContext }
     var currentIndex = -1
+        set(value) {
+            field = value
+            currentPlayedMedia.postValue(mediaList.getMedia(value))
+        }
     private var nextIndex = -1
     private var prevIndex = -1
     var startupIndex = -1    



More information about the Android mailing list