[Android] Fix audio global progress flickering and Locale format

Nicolas Pomepuy git at videolan.org
Tue Jun 15 09:32:29 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jun 14 15:49:11 2021 +0200| [80bfee2a5e53e5b81db02fc55b30b321cd34a854] | committer: Nicolas Pomepuy

Fix audio global progress flickering and Locale format

Fixes #2050

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

 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt  | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index dd7eaa1b0..82a0c780c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -77,7 +77,10 @@ import org.videolan.vlc.util.share
 import org.videolan.vlc.viewmodels.BookmarkModel
 import org.videolan.vlc.viewmodels.PlaybackProgress
 import org.videolan.vlc.viewmodels.PlaylistModel
+import java.text.DateFormat.SHORT
+import java.text.DateFormat.getTimeInstance
 import java.util.*
+import kotlin.math.absoluteValue
 
 private const val TAG = "VLC/AudioPlayer"
 private const val SEARCH_TIMEOUT_MILLIS = 10000L
@@ -106,6 +109,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
 
     private lateinit var abRepeatAddMarker: Button
     private var audioPlayProgressMode:Boolean = false
+    private var lastEndsAt = -1L
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -377,21 +381,22 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
                 val currentProgressText = if (progressTimeText.isNullOrEmpty()) "0:00" else progressTimeText
 
                 val textTrack = getString(R.string.track_index, "${playlistModel.currentMediaPosition + 1} / ${medias.size}")
-                val textProgress = if (audioPlayProgressMode)
+
+                val textProgress = if (audioPlayProgressMode) {
+                    val endsAt = System.currentTimeMillis() + totalTime - progressTime
+                    if ((lastEndsAt - endsAt).absoluteValue > 1) lastEndsAt = endsAt
                     getString(
                         R.string.audio_queue_progress_finished,
-                        DateFormat.format("hh:mm:ss a", Date(System.currentTimeMillis() + totalTime - progressTime))
+                        getTimeInstance(java.text.DateFormat.MEDIUM).format(lastEndsAt)
                     )
-                else
-                    if (showRemainingTime && totalTime > 0) getString(
-                        R.string.audio_queue_progress_remaining,
-                        "$currentProgressText"
+                } else if (showRemainingTime && totalTime > 0) getString(
+                    R.string.audio_queue_progress_remaining,
+                    "$currentProgressText"
+                )
+                else getString(
+                        R.string.audio_queue_progress,
+                        if (totalTimeText.isNullOrEmpty()) "$currentProgressText" else "$currentProgressText / $totalTimeText"
                     )
-                    else
-                        getString(
-                            R.string.audio_queue_progress,
-                            if (totalTimeText.isNullOrEmpty()) "$currentProgressText" else "$currentProgressText / $totalTimeText"
-                        )
                 "$textTrack  •  $textProgress"
             }
             binding.audioPlayProgress.text = text



More information about the Android mailing list