[Android] Cache current playback time value

Geoffrey Métais git at videolan.org
Thu Feb 8 18:06:14 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sat Feb  3 17:52:15 2018 +0100| [09f502ff31bcdd3d77616425556cea6a7533a795] | committer: Geoffrey Métais

Cache current playback time value

> https://code.videolan.org/videolan/vlc-android/commit/09f502ff31bcdd3d77616425556cea6a7533a795
---

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

diff --git a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index 44c1a04cd..2fe7f3d94 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -32,6 +32,8 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
         private set
     @Volatile var hasRenderer = false
         private set
+    @Volatile var currentTime = 0L
+        private set
 
     fun getVout(): IVLCVout? = mediaplayer.vlcVout
 
@@ -52,6 +54,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
     fun stop() {
         if (mediaplayer.hasMedia()) mediaplayer.stop()
         playbackState = PlaybackStateCompat.STATE_STOPPED
+        currentTime = 0
     }
 
     fun releaseMedia() = mediaplayer.media?.let {
@@ -64,6 +67,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
         mediaplayerEventListener = listener
         seekable = true
         pausable = true
+        currentTime = 0L
         mediaplayer.setEventListener(null)
         mediaplayer.media = media.apply { if (hasRenderer) parse() }
         mediaplayer.setEventListener(this at PlayerController)
@@ -169,6 +173,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
             } else player.release()
         }
         playbackState = PlaybackStateCompat.STATE_STOPPED
+        currentTime = 0L
     }
 
     fun setSlaves(media: MediaWrapper) = launch {
@@ -190,7 +195,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
         switchToVideo = false
     }
 
-    fun getTime() = if (mediaplayer.hasMedia()) mediaplayer.time else 0L
+    fun getTime() = currentTime
 
     fun setRate(rate: Float, save: Boolean) {
         mediaplayer.rate = rate
@@ -262,6 +267,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
             MediaPlayer.Event.EncounteredError -> playbackState = PlaybackStateCompat.STATE_STOPPED
             MediaPlayer.Event.PausableChanged -> pausable = event.pausable
             MediaPlayer.Event.SeekableChanged -> seekable = event.seekable
+            MediaPlayer.Event.TimeChanged -> currentTime = event.timeChanged
         }
         mediaplayerEventListener?.onEvent(event)
     }



More information about the Android mailing list