[Android] Cache current playback time value
Geoffrey Métais
git at videolan.org
Wed Feb 21 16:25:36 CET 2018
vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Sat Feb 3 17:52:15 2018 +0100| [2fde878007cbbb032a56390847b936548003cf99] | committer: Geoffrey Métais
Cache current playback time value
Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>
> https://code.videolan.org/videolan/vlc-android/commit/2fde878007cbbb032a56390847b936548003cf99
---
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