[Android] Force saving the end of the current media and prevent further saves
Nicolas Pomepuy
git at videolan.org
Mon Dec 12 08:28:46 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Dec 6 09:06:17 2022 +0100| [49b24f1674a17ec3067fc7872a50b7aa3699a8d9] | committer: Nicolas Pomepuy
Force saving the end of the current media and prevent further saves
> https://code.videolan.org/videolan/vlc-android/commit/49b24f1674a17ec3067fc7872a50b7aa3699a8d9
---
.../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt | 11 +++++++----
1 file changed, 7 insertions(+), 4 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 ae6b16ed8f..b56c7b2ce7 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -41,6 +41,7 @@ private const val PLAYLIST_AUDIO_REPEAT_MODE_KEY = "audio_repeat_mode"
private const val PLAYLIST_VIDEO_REPEAT_MODE_KEY = "video_repeat_mode"
class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventListener, IMedia.EventListener, CoroutineScope {
+ private var endReachedFor: String? = null
override val coroutineContext = Dispatchers.Main.immediate + SupervisorJob()
companion object {
@@ -525,7 +526,8 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
service.executeUpdate(true)
}
- fun saveMediaMeta() = launch(start = CoroutineStart.UNDISPATCHED) outerLaunch@ {
+ fun saveMediaMeta(end:Boolean = false) = launch(start = CoroutineStart.UNDISPATCHED) outerLaunch@ {
+ if (endReachedFor != null && endReachedFor == getCurrentMedia()?.uri.toString() && !end) return at outerLaunch
val titleIdx = player.getTitleIdx()
val currentMedia = getCurrentMedia() ?: return at outerLaunch
if (currentMedia.uri.scheme.isSchemeFD()) return at outerLaunch
@@ -544,12 +546,12 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
if (length == 0L) {
media.time = -1L
media.position = player.lastPosition
- medialibrary.setLastPosition(media.id, media.position)
+ medialibrary.setLastPosition(media.id, if (end) 1F else media.position)
} else {
//todo verify that this info is persisted in DB
if (media.length <= 0 && length > 0) media.length = length
try {
- when (medialibrary.setLastTime(media.id, time)) {
+ when (medialibrary.setLastTime(media.id, if (end) length else time)) {
Medialibrary.ML_SET_TIME_ERROR -> {
}
Medialibrary.ML_SET_TIME_END, Medialibrary.ML_SET_TIME_BEGIN -> media.time = 0
@@ -1009,7 +1011,8 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
clearABRepeat()
getCurrentMedia()?.addFlags(MediaWrapper.MEDIA_FROM_START)
if (currentIndex != nextIndex) {
- saveMediaMeta()
+ endReachedFor = getCurrentMedia()?.uri.toString()
+ saveMediaMeta(true)
if (isBenchmark) player.setPreviousStats()
if (nextIndex == -1) savePosition(reset = true)
}
More information about the Android
mailing list