[Android] TV: Fix resume card generation
Geoffrey Métais
git at videolan.org
Wed May 15 18:35:27 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed May 15 17:27:14 2019 +0200| [4f3173b0ad026c6c3223a66c218205f928b406af] | committer: Geoffrey Métais
TV: Fix resume card generation
> https://code.videolan.org/videolan/vlc-android/commit/4f3173b0ad026c6c3223a66c218205f928b406af
---
.../src/org/videolan/vlc/media/PlaylistManager.kt | 39 +++++++++++-----------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 22383559b..caedfaab0 100644
--- a/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -209,8 +209,11 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
videoBackground = false
getCurrentMedia()?.let {
savePosition()
- saveMediaMeta()
- if (AndroidDevices.isAndroidTv && AndroidUtil.isOOrLater && !isAudioList()) setResumeProgram(service.applicationContext, it)
+ val audio = isAudioList() // check before dispatching in saveMediaMeta()
+ launch(start = CoroutineStart.UNDISPATCHED) {
+ saveMediaMeta().join()
+ if (AndroidDevices.isAndroidTv && AndroidUtil.isOOrLater && !audio) setResumeProgram(service.applicationContext, it)
+ }
}
mediaList.removeEventListener(this)
previous.clear()
@@ -394,30 +397,28 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
service.executeUpdate()
}
- fun saveMediaMeta() {
- val currentMedia = getCurrentMedia() ?: return
- if (currentMedia.uri.scheme == "fd") return
+ fun saveMediaMeta() = launch(start = CoroutineStart.UNDISPATCHED) {
+ val currentMedia = getCurrentMedia() ?: return at launch
+ if (currentMedia.uri.scheme == "fd") return at launch
//Save progress
val time = player.getCurrentTime()
val length = player.getLength()
val canSwitchToVideo = player.canSwitchToVideo()
val rate = player.getRate()
- launch {
- val media = withContext(Dispatchers.IO) { medialibrary.findMedia(currentMedia) }
- if (media === null || media.id == 0L) return at launch
- if (media.type == MediaWrapper.TYPE_VIDEO || canSwitchToVideo || media.isPodcast) {
- var progress = time / length.toFloat()
- if (progress > 0.95f || length - time < 10000) {
- //increase seen counter if more than 95% of the media have been seen
- //and reset progress to 0
- launch(Dispatchers.IO) { media.setLongMeta(MediaWrapper.META_SEEN, media.seen+1) }
- progress = 0f
- }
- media.time = if (progress == 0f) 0L else time
- launch(Dispatchers.IO) { media.setLongMeta(MediaWrapper.META_PROGRESS, media.time) }
+ val media = withContext(Dispatchers.IO) { medialibrary.findMedia(currentMedia) }
+ if (media === null || media.id == 0L) return at launch
+ if (media.type == MediaWrapper.TYPE_VIDEO || canSwitchToVideo || media.isPodcast) {
+ var progress = time / length.toFloat()
+ if (progress > 0.95f || length - time < 10000) {
+ //increase seen counter if more than 95% of the media have been seen
+ //and reset progress to 0
+ launch(Dispatchers.IO) { media.setLongMeta(MediaWrapper.META_SEEN, media.seen+1) }
+ progress = 0f
}
- launch(Dispatchers.IO) { media.setStringMeta(MediaWrapper.META_SPEED, rate.toString()) }
+ media.time = if (progress == 0f) 0L else time
+ launch(Dispatchers.IO) { media.setLongMeta(MediaWrapper.META_PROGRESS, media.time) }
}
+ launch(Dispatchers.IO) { media.setStringMeta(MediaWrapper.META_SPEED, rate.toString()) }
}
fun setSpuTrack(index: Int) {
More information about the Android
mailing list