[Android] 'Stop after this track' feature

Geoffrey Métais git at videolan.org
Mon Sep 10 17:03:54 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Sep 10 17:03:30 2018 +0200| [3c942e100d431fa454ff8b404ae0c1a96b6d3dac] | committer: Geoffrey Métais

'Stop after this track' feature

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

 vlc-android/res/values/strings.xml                     |  1 +
 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt      |  3 ++-
 .../src/org/videolan/vlc/gui/dialogs/ContextSheet.kt   |  1 +
 .../src/org/videolan/vlc/media/PlaylistManager.kt      | 18 +++++++++++++-----
 vlc-android/src/org/videolan/vlc/util/Constants.kt     |  1 +
 5 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index fc35f5793..5530afb24 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -619,4 +619,5 @@
     <string name="otg_device_title">OTG device</string>
     <string name="browser">Browser</string>
     <string name="ab_repeat">A-B repeat</string>
+    <string name="stop_after_this">Stop after this track</string>
 </resources>
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index bc8dae830..02860c918 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -180,6 +180,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
                     UiTools.snackerWithCancel(it, message, null, cancelAction)
                     service?.remove(position)
                 }
+                CTX_STOP_AFTER_THIS -> service?.playlistManager?.stopAfter = position
             }
         }
     }
@@ -187,7 +188,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
     override fun onPopupMenu(anchor: View, position: Int, media: MediaWrapper) {
         val activity = activity
         if (activity === null || position >= playlistAdapter.itemCount) return
-        val flags = CTX_REMOVE_FROM_PLAYLIST or CTX_SET_RINGTONE or CTX_ADD_TO_PLAYLIST
+        val flags = CTX_REMOVE_FROM_PLAYLIST or CTX_SET_RINGTONE or CTX_ADD_TO_PLAYLIST or CTX_STOP_AFTER_THIS
         showContext(activity, ctxReceiver, position, media.title, flags)
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
index eed5cba36..de81a69c5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
@@ -95,6 +95,7 @@ class ContextSheet : BottomSheetDialogFragment() {
         if (flags and CTX_FAV_EDIT != 0) add(Simple(CTX_FAV_EDIT, getString(R.string.favorites_edit), R.drawable.ic_ctx_fav_edit_normal))
         if (flags and CTX_FAV_REMOVE != 0) add(Simple(CTX_FAV_REMOVE, getString(R.string.favorites_remove), R.drawable.ic_ctx_fav_remove_normal))
         if (flags and CTX_REMOVE_FROM_PLAYLIST != 0) add(Simple(CTX_REMOVE_FROM_PLAYLIST, getString(R.string.remove), R.drawable.ic_ctx_remove_from_playlist_normal))
+        if (flags and CTX_STOP_AFTER_THIS != 0) add(Simple(CTX_STOP_AFTER_THIS, getString(R.string.stop_after_this), R.drawable.ic_pause_normal))
     }
 
     inner class ContextAdapter : RecyclerView.Adapter<ContextAdapter.ViewHolder>() {
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 6cf5d6e30..c9bb91cc7 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -52,6 +52,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     private var nextIndex = -1
     private var prevIndex = -1
     private var previous = Stack<Int>()
+    var stopAfter = -1
     var repeating = REPEAT_NONE
     var shuffling = false
     var videoBackground = false
@@ -119,6 +120,8 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
         // Add handler after loading the list
         mediaList.addEventListener(this)
+        stopAfter = -1
+        clearABRepeat()
         launch(UI.immediate) {
             playIndex(position)
             onPlaylistLoaded()
@@ -195,6 +198,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
 
     fun stop(systemExit: Boolean = false) {
         clearABRepeat()
+        stopAfter = -1
         getCurrentMedia()?.let {
             savePosition()
             saveMediaMeta()
@@ -710,17 +714,21 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                 }
                 MediaPlayer.Event.Paused -> medialibrary.resumeBackgroundOperations()
                 MediaPlayer.Event.EndReached -> {
+                    clearABRepeat()
                     if (currentIndex != nextIndex) {
                         saveMediaMeta()
                         if (isBenchmark) player.setPreviousStats()
                         if (nextIndex == -1) savePosition(true)
                     }
-                    determinePrevAndNextIndices(true)
-                    if (!hasNext()) getCurrentMedia()?.let {
-                        if (AndroidDevices.isAndroidTv && AndroidUtil.isOOrLater && !isAudioList()) setResumeProgram(service.applicationContext, it)
+                    if (stopAfter == currentIndex) {
+                        stop()
+                    } else {
+                        determinePrevAndNextIndices(true)
+                        if (!hasNext()) getCurrentMedia()?.let {
+                            if (AndroidDevices.isAndroidTv && AndroidUtil.isOOrLater && !isAudioList()) setResumeProgram(service.applicationContext, it)
+                        }
+                        next()
                     }
-                    clearABRepeat()
-                    next()
                 }
                 MediaPlayer.Event.EncounteredError -> {
                     service.showToast(service.getString(
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index 8fb153de1..3d0da7059 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -152,6 +152,7 @@ const val CTX_FAV_REMOVE = 1 shl 14
 const val CTX_CUSTOM_REMOVE = 1 shl 15
 const val CTX_ITEM_DL = 1 shl 16
 const val CTX_REMOVE_FROM_PLAYLIST = 1 shl 17
+const val CTX_STOP_AFTER_THIS = 1 shl 18
 
 const val CTX_VIDEO_FLAGS = CTX_APPEND or CTX_DELETE or CTX_DOWNLOAD_SUBTITLES or CTX_INFORMATION or CTX_PLAY_ALL or CTX_PLAY_AS_AUDIO
 const val CTX_TRACK_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_INFORMATION or CTX_PLAY_ALL or CTX_ADD_TO_PLAYLIST or CTX_SET_RINGTONE



More information about the Android mailing list