[Android] Correctly save current video play queue
Geoffrey Métais
git at videolan.org
Thu Feb 20 13:35:10 CET 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 17 15:56:41 2020 +0100| [74dd128ea64de11ea6e98795d50bff79fc5d6709] | committer: Geoffrey Métais
Correctly save current video play queue
> https://code.videolan.org/videolan/vlc-android/commit/74dd128ea64de11ea6e98795d50bff79fc5d6709
---
.../vlc-android/src/org/videolan/vlc/PlaybackService.kt | 6 +++---
.../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt | 5 ++---
.../src/org/videolan/vlc/media/PlaylistManager.kt | 12 ++++++------
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 7bedc7af9..8d0addd18 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -570,7 +570,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
handler.removeCallbacksAndMessages(null)
if (this::mediaSession.isInitialized) mediaSession.release()
//Call it once mediaSession is null, to not publish playback state
- stop(true)
+ stop(systemExit = true)
unregisterReceiver(receiver)
playlistManager.onServiceDestroyed()
@@ -781,8 +781,8 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
@MainThread
@JvmOverloads
- fun stop(systemExit: Boolean = false) {
- playlistManager.stop(systemExit)
+ fun stop(systemExit: Boolean = false, video: Boolean = false) {
+ playlistManager.stop(systemExit, video)
}
private fun initMediaSession() {
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 8c76742e5..f2f633d43 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
@@ -776,7 +776,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
val vlcVout = vout
if (vlcVout != null && vlcVout.areViewsAttached()) {
if (isPlayingPopup) {
- stop()
+ stop(video = true)
} else
vlcVout.detachViews()
}
@@ -860,7 +860,6 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
playbackStarted = false
handler.removeCallbacksAndMessages(null)
- mediaplayer.detachViews()
if (hasMedia() && switchingView) {
if (BuildConfig.DEBUG) Log.d(TAG, "mLocation = \"$videoUri\"")
if (switchToPopup)
@@ -881,7 +880,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
else
savedTime -= 2000 // go back 2 seconds, to compensate loading time
}
- stop()
+ stop(video = true)
}
}
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 848aa3be2..cbea02226 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -213,12 +213,12 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
launch { playIndex(currentIndex) }
}
- fun stop(systemExit: Boolean = false) {
+ fun stop(systemExit: Boolean = false, video: Boolean = false) {
clearABRepeat()
stopAfter = -1
videoBackground = false
val job = getCurrentMedia()?.let {
- savePosition()
+ savePosition(video = video)
val audio = isAudioList() // check before dispatching in saveMediaMeta()
launch(start = CoroutineStart.UNDISPATCHED) {
saveMediaMeta().join()
@@ -645,10 +645,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
}
@Synchronized
- private fun savePosition(reset: Boolean = false) {
+ private fun savePosition(reset: Boolean = false, video: Boolean = false) {
if (!hasMedia()) return
val editor = settings.edit()
- val audio = isAudioList()
+ val audio = !video && isAudioList()
editor.putBoolean(if (audio) "audio_shuffling" else "media_shuffling", shuffling)
editor.putInt(if (audio) "position_in_audio_list" else "position_in_media_list", if (reset) 0 else currentIndex)
editor.putLong(if (audio) "position_in_song" else "position_in_media", if (reset) 0L else player.getCurrentTime())
@@ -789,7 +789,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
if (newMedia) {
loadMediaMeta(mw)
saveMediaList()
- savePosition(true)
+ savePosition(reset = true)
saveCurrentMedia()
newMedia = false
if (player.hasRenderer || !player.isVideoPlaying()) showAudioPlayer.value = true
@@ -801,7 +801,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
if (currentIndex != nextIndex) {
saveMediaMeta()
if (isBenchmark) player.setPreviousStats()
- if (nextIndex == -1) savePosition(true)
+ if (nextIndex == -1) savePosition(reset = true)
}
if (stopAfter == currentIndex) {
stop()
More information about the Android
mailing list