[Android] Fix the audio player previous behavior in case of seekable strams

Nicolas Pomepuy git at videolan.org
Thu Apr 1 13:18:54 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Mar 31 10:26:12 2021 +0200| [2741304411877b9aee9f3d3e73886504df0ba9e6] | committer: Nicolas Pomepuy

Fix the audio player previous behavior in case of seekable strams

Fixes #1846

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

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

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 5d4da0a7d..f4b16da56 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -73,6 +73,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     val abRepeatOn by lazy(LazyThreadSafetyMode.NONE) { MutableLiveData<Boolean>().apply { value = false } }
     val videoStatsOn by lazy(LazyThreadSafetyMode.NONE) { MutableLiveData<Boolean>().apply { value = false } }
     val delayValue by lazy(LazyThreadSafetyMode.NONE) { MutableLiveData<DelayValues>().apply { value = DelayValues() } }
+    private var lastPrevious = -1L
 
     private val mediaFactory = FactoryManager.getFactory(IMediaFactory.factoryId) as IMediaFactory
 
@@ -260,7 +261,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     @MainThread
     fun previous(force : Boolean) {
         if (hasPrevious() && currentIndex > 0 &&
-                (force || !player.seekable || player.getCurrentTime() < PREVIOUS_LIMIT_DELAY)) {
+                ((force || !player.seekable || (player.getCurrentTime() < PREVIOUS_LIMIT_DELAY) || (lastPrevious != -1L && System.currentTimeMillis() - lastPrevious <  PREVIOUS_LIMIT_DELAY)))) {
             val size = mediaList.size()
             currentIndex = prevIndex
             if (previous.size > 0) previous.pop()
@@ -270,7 +271,11 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 return
             }
             launch { playIndex(currentIndex) }
-        } else player.setPosition(0F)
+            lastPrevious = -1L
+        } else {
+            player.setPosition(0F)
+            lastPrevious = System.currentTimeMillis()
+        }
     }
 
     @MainThread



More information about the Android mailing list