[Android] Fix seeking when setTime should be called

Nicolas Pomepuy git at videolan.org
Fri Jul 9 06:44:16 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jun 28 14:00:43 2021 +0200| [29390e3e63b83de9b8b208c66b03ba4409e949c1] | committer: Nicolas Pomepuy

Fix seeking when setTime should be called

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

 application/vlc-android/src/org/videolan/vlc/PlaybackService.kt     | 6 +++---
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt           | 3 +--
 .../vlc-android/src/org/videolan/vlc/media/PlayerController.kt      | 6 ++----
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 321fbd27a..40d70b705 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1339,10 +1339,10 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
 
     @MainThread
     @JvmOverloads
-    fun seek(position: Long, length: Double = this.length.toDouble(), fromUser: Boolean = false) {
-        if (length > 0.0) setPosition((position / length).toFloat()) else setPosition((position.toFloat() / NO_LENGTH_PROGRESS_MAX.toFloat()))
+    fun seek(time: Long, length: Double = this.length.toDouble(), fromUser: Boolean = false) {
+        if (length > 0.0) this.time = time else setPosition((time.toFloat() / NO_LENGTH_PROGRESS_MAX.toFloat()))
         if (fromUser) {
-            publishState(position)
+            publishState(time)
         }
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 2a7d0c2d9..31d17ee11 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -33,7 +33,6 @@ import android.content.res.Configuration
 import android.media.AudioManager
 import android.net.Uri
 import android.os.*
-import android.support.v4.media.session.PlaybackStateCompat
 import android.text.Editable
 import android.text.TextWatcher
 import android.util.DisplayMetrics
@@ -276,7 +275,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
             if (!isFinishing && fromUser && service?.isSeekable == true) {
                 seek(progress.toLong(), fromUser)
-                overlayDelegate.showInfo(Tools.millisToString(progress.toLong()), 1000)
+                if (service?.length != 0L) overlayDelegate.showInfo(Tools.millisToString(progress.toLong()), 1000)
             }
             if (fromUser) {
                 overlayDelegate.showOverlay(true)
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt b/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
index 4b5137a65..d4615ff14 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlayerController.kt
@@ -3,7 +3,6 @@ package org.videolan.vlc.media
 import android.content.Context
 import android.net.Uri
 import android.support.v4.media.session.PlaybackStateCompat
-import android.util.Log
 import android.widget.Toast
 import androidx.annotation.MainThread
 import androidx.core.net.toUri
@@ -108,9 +107,8 @@ class PlayerController(val context: Context) : IVLCVout.Callback, MediaPlayer.Ev
         release(mp)
     }
 
-    fun seek(position: Long, length: Double = getLength().toDouble()) {
-        val pos = if (length > 0.0) (position / length).toFloat() else (position / NO_LENGTH_PROGRESS_MAX).toFloat()
-        setPosition(pos)
+    fun seek(time: Long, length: Double = getLength().toDouble()) {
+        if (length > 0.0) setTime(time) else setPosition((time / NO_LENGTH_PROGRESS_MAX).toFloat())
     }
 
     fun setPosition(position: Float) {



More information about the Android mailing list