[Android] Player: Init progress with start time value

Geoffrey Métais git at videolan.org
Wed Apr 10 14:58:12 CEST 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr 10 10:26:34 2019 +0200| [f60666c158f60100edf44f07d8409006b209546e] | committer: Geoffrey Métais

Player: Init progress with start time value

(cherry picked from commit 44d64429e2368cd5906939cce9bc043704007ae9)

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

 vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt |  6 +++---
 vlc-android/src/org/videolan/vlc/media/PlayerController.kt   | 10 +++++-----
 vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt    |  8 ++++----
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt b/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt
index 161535352..839324cbc 100644
--- a/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt
+++ b/vlc-android/src/org/videolan/vlc/PreviewVideoInputService.kt
@@ -53,8 +53,8 @@ class PreviewVideoInputService : TvInputService(), CoroutineScope {
                 }
                 try {
                     val media = Media(VLCInstance.get(this at PreviewVideoInputService), mw.uri)
-                    val start = if (mw.length <= 0L) 0 else mw.length.random()/1000
-                    media.addOption(":start-time=$start")
+                    val start = if (mw.length <= 0L) 0L else mw.length.random()
+                    media.addOption(":start-time=${start/1000L}")
                     player.getVout()?.apply {
                         setVideoSurface(surface, null)
                         attachViews(null)
@@ -62,7 +62,7 @@ class PreviewVideoInputService : TvInputService(), CoroutineScope {
                     }
                     player.setVideoAspectRatio(null)
                     player.setVideoScale(0f)
-                    player.startPlayback(media, this at PreviewSession)
+                    player.startPlayback(media, this at PreviewSession, start)
                     notifyVideoAvailable()
                 } catch (e: IOException) {
                     Log.e(TAG, "Could not prepare media player", e)
diff --git a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index 5d96abba4..2cfe44bc8 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -73,9 +73,9 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
     }
 
     private var mediaplayerEventListener: MediaPlayerEventListener? = null
-    internal suspend fun startPlayback(media: Media, listener: MediaPlayerEventListener) {
+    internal suspend fun startPlayback(media: Media, listener: MediaPlayerEventListener, time: Long) {
         mediaplayerEventListener = listener
-        resetPlaybackState(media.duration)
+        resetPlaybackState(time, media.duration)
         mediaplayer.setEventListener(null)
         withContext(Dispatchers.IO) { if (!mediaplayer.isReleased) mediaplayer.media = media.apply { if (hasRenderer) parse() } }
         mediaplayer.setEventListener(this at PlayerController)
@@ -86,11 +86,11 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
         }
     }
 
-    private fun resetPlaybackState(duration: Long) {
+    private fun resetPlaybackState(time: Long, duration: Long) {
         seekable = true
         pausable = true
-        lastTime = 0L
-        updateProgress(0L, duration)
+        lastTime = time
+        updateProgress(time, duration)
     }
 
     @MainThread
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 52811a88f..407ffe160 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -294,7 +294,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             }
             val start = getStartTime(mw)
             val media = Media(VLCInstance.get(service), uri)
-            media.addOption(":start-time=$start")
+            media.addOption(":start-time=${start/1000L}")
             VLCOptions.setMediaOptions(media, ctx, flags or mw.flags)
             /* keeping only video during benchmark */
             if (isBenchmark) {
@@ -306,7 +306,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 }
             }
             media.setEventListener(this at PlaylistManager)
-            player.startPlayback(media, mediaplayerEventListener)
+            player.startPlayback(media, mediaplayerEventListener, start)
             player.setSlaves(media, mw)
             newMedia = true
             determinePrevAndNextIndices()
@@ -325,7 +325,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 if (id != 0L) medialibrary.increasePlayCount(id)
             }
         } else { //Start VideoPlayer for first video, it will trigger playIndex when ready.
-            player.stop()
+            if (player.isPlaying()) player.stop()
             VideoPlayerActivity.startOpened(ctx, mw.uri, currentIndex)
         }
     }
@@ -632,7 +632,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             else -> savedTime
         }
         savedTime = 0L
-        return start/1000L
+        return start
     }
 
     @Synchronized



More information about the Android mailing list