[Android] Prevent saving 0 for videos if the MediaPlayer has been reset in the meantime
Nicolas Pomepuy
git at videolan.org
Tue Jun 14 15:37:05 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun 9 06:31:23 2022 +0200| [044efa86f7697ab0123edaed7ed7c475df15e46a] | committer: Duncan McNamara
Prevent saving 0 for videos if the MediaPlayer has been reset in the meantime
Fixes #2524
> https://code.videolan.org/videolan/vlc-android/commit/044efa86f7697ab0123edaed7ed7c475df15e46a
---
.../src/org/videolan/vlc/media/PlaylistManager.kt | 34 ++++++++++++----------
1 file changed, 18 insertions(+), 16 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 631bb2a1b..fd19d6d81 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -521,26 +521,28 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
val media = medialibrary.findMedia(currentMedia) ?: return at innerLaunch
if (media.id == 0L) return at innerLaunch
if (titleIdx > 0) media.setLongMeta(MediaWrapper.META_TITLE, titleIdx.toLong())
- if (media.type == MediaWrapper.TYPE_VIDEO || canSwitchToVideo || media.isPodcast) {
- if (length == 0L) {
- media.time = -1L
- media.position = player.lastPosition
- medialibrary.setLastPosition(media.id, 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)) {
- Medialibrary.ML_SET_TIME_ERROR -> {
+ //checks if the [MediaPlayer] has not been reset in the meantime to prevent saving 0
+ if (time != 0L || player.isPlaying())
+ if (media.type == MediaWrapper.TYPE_VIDEO || canSwitchToVideo || media.isPodcast) {
+ if (length == 0L) {
+ media.time = -1L
+ media.position = player.lastPosition
+ medialibrary.setLastPosition(media.id, 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)) {
+ Medialibrary.ML_SET_TIME_ERROR -> {
+ }
+ Medialibrary.ML_SET_TIME_END, Medialibrary.ML_SET_TIME_BEGIN -> media.time = 0
+ Medialibrary.ML_SET_TIME_AS_IS -> media.time = time
}
- Medialibrary.ML_SET_TIME_END, Medialibrary.ML_SET_TIME_BEGIN -> media.time = 0
- Medialibrary.ML_SET_TIME_AS_IS -> media.time = time
+ } catch (e: NullPointerException) {
+ VLCCrashHandler.saveLog(e, "NullPointerException in PlaylistManager saveMediaMeta")
}
- } catch (e: NullPointerException) {
- VLCCrashHandler.saveLog(e, "NullPointerException in PlaylistManager saveMediaMeta")
}
}
- }
media.setStringMeta(MediaWrapper.META_SPEED, rate.toString())
}
More information about the Android
mailing list