[Android] Add a play queue time indicator "Ends at" mode

Nicolas Pomepuy git at videolan.org
Fri Feb 5 10:07:18 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Feb  2 10:59:55 2021 +0100| [02bc476e7d2a3a48fcbf6a58697bee4d5882da91] | committer: Nicolas Pomepuy

Add a play queue time indicator "Ends at" mode

Fixes #1610

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

 application/resources/src/main/res/values/strings.xml    |  1 +
 .../tools/src/main/java/org/videolan/tools/Settings.kt   |  1 +
 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt        | 16 ++++++++++++++--
 .../src/org/videolan/vlc/viewmodels/PlaylistModel.kt     |  7 +++++++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 376e4a27f..8c4804601 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -714,6 +714,7 @@
     <string name="subtitle_delay_end">Text seen</string>
     <string name="track_index">Track: %s</string>
     <string name="audio_queue_progress">Progress: %s</string>
+    <string name="audio_queue_progress_finished">Ends at: %s</string>
     <string name="sortby_track">Track</string>
     <string name="this_folder">Add this folder</string>
     <string name="all_subfolders">Add this folder and subfolders</string>
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 3fb9d8fe7..5bc162810 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -101,6 +101,7 @@ const val RESUME_PLAYBACK = "resume_playback"
 const val AUDIO_DUCKING = "audio_ducking"
 
 const val AUDIO_DELAY_GLOBAL = "audio_delay_global"
+const val AUDIO_PLAY_PROGRESS_MODE = "audio_play_progress_mode"
 
 class DeviceInfo(context: Context) {
     val pm = context.packageManager
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 52c280b46..c04c0e915 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
@@ -30,6 +30,7 @@ import android.os.Vibrator
 import android.support.v4.media.session.PlaybackStateCompat
 import android.text.Editable
 import android.text.TextWatcher
+import android.text.format.DateFormat
 import android.view.LayoutInflater
 import android.view.MotionEvent
 import android.view.View
@@ -76,6 +77,7 @@ import org.videolan.vlc.util.launchWhenStarted
 import org.videolan.vlc.util.share
 import org.videolan.vlc.viewmodels.PlaybackProgress
 import org.videolan.vlc.viewmodels.PlaylistModel
+import java.util.*
 
 private const val TAG = "VLC/AudioPlayer"
 private const val SEARCH_TIMEOUT_MILLIS = 10000L
@@ -101,6 +103,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
     private lateinit var playToPauseSmall: AnimatedVectorDrawableCompat
 
     private lateinit var abRepeatAddMarker: Button
+    private var audioPlayProgressMode:Boolean = false
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -179,6 +182,12 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
             playlistModel.service?.playlistManager?.setABRepeatValue(binding.timeline.progress.toLong())
         }
 
+        audioPlayProgressMode = Settings.getInstance(requireActivity()).getBoolean(AUDIO_PLAY_PROGRESS_MODE, false)
+        binding.audioPlayProgress.setOnClickListener {
+            audioPlayProgressMode = !audioPlayProgressMode
+            Settings.getInstance(requireActivity()).putSingle(AUDIO_PLAY_PROGRESS_MODE, audioPlayProgressMode)
+            playlistModel.progress.value?.let { updateProgress(it) }
+        }
 
     }
 
@@ -321,11 +330,14 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
                 if (playlistModel.currentMediaPosition == -1) return at withContext ""
                 val elapsedTracksTime = playlistModel.previousTotalTime ?: return at withContext ""
                 val totalTime = elapsedTracksTime + progress.time
-                val totalTimeText = Tools.millisToString(totalTime, true, false, false)
+                val totalTimeText = Tools.millisToString(totalTime, true, true, false)
                 val currentProgressText = if (totalTimeText.isNullOrEmpty()) "0s" else totalTimeText
 
                 val textTrack = getString(R.string.track_index, "${playlistModel.currentMediaPosition + 1} / ${medias.size}")
-                val textProgress = getString(R.string.audio_queue_progress,
+                val textProgress = if (audioPlayProgressMode)
+                        getString(R.string.audio_queue_progress_finished,DateFormat.getTimeFormat(requireContext()).format(Date(System.currentTimeMillis() + playlistModel.getTotalTime() - totalTime)))
+                    else
+                        getString(R.string.audio_queue_progress,
                         if (playlistModel.totalTime.isNullOrEmpty()) "$currentProgressText" else "$currentProgressText / ${playlistModel.totalTime}")
                 "$textTrack  •  $textProgress"
             }
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
index c4f696a6f..9fe9891ae 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
@@ -242,6 +242,13 @@ class PlaylistModel : ViewModel(), PlaybackService.Callback by EmptyPBSCallback
         totalTime = Tools.millisToString(totalLength, true, false, false)
     }
 
+    fun getTotalTime():Long {
+            val mediaList = medias ?: return 0L
+            return mediaList.asSequence()
+                    .map { it.length }
+                    .sum()
+    }
+
     companion object {
         fun get(fragment: Fragment) = ViewModelProviders.of(fragment.requireActivity()).get(PlaylistModel::class.java)
     }



More information about the Android mailing list