Fix playback progress on downloads when playback has already started (#243)

* Fix playback progress when playback has already started

Before, if an item had playback progress when the download was started, the player would jump to the end of the item immediately when playing from downloads.

* Fix syncing playback progress when remote is ahead

* Fix playback progress when playback has already started

Before, if an item had playback progress when the download was started, the player would jump to the end of the item immediately when playing from downloads.

* Fix syncing playback progress when remote is ahead
This commit is contained in:
Jcuhfehl 2023-01-26 19:28:45 +01:00 committed by GitHub
parent 1a55519ac5
commit 12e743afcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -237,7 +237,7 @@ suspend fun syncPlaybackProgress(
val localPlayedPercentage = it.item?.playedPercentage
val item = jellyfinRepository.getItem(it.itemId)
val remotePlaybackProgress = item.userData?.playbackPositionTicks?.div(10000)
val remotePlaybackProgress = item.userData?.playbackPositionTicks
val remotePlayedPercentage = item.userData?.playedPercentage
var playbackProgress: Long = 0
@ -267,7 +267,7 @@ suspend fun syncPlaybackProgress(
)
jellyfinRepository.postPlaybackProgress(
it.itemId,
playbackProgress.times(10000),
playbackProgress,
true
)
Timber.d("Percentage: $playedPercentage")

View file

@ -149,7 +149,7 @@ constructor(
Timber.e(e)
}
player.setMediaItems(mediaItems, currentMediaItemIndex, items.getOrNull(currentMediaItemIndex)?.playbackPosition ?: C.TIME_UNSET)
player.setMediaItems(mediaItems, currentMediaItemIndex, items.getOrNull(currentMediaItemIndex)?.playbackPosition?.div(10000) ?: C.TIME_UNSET)
if (!appPreferences.playerMpv || !playFromDownloads)
player.prepare() // TODO: This line causes a crash when playing from downloads with MPV
player.play()
@ -185,7 +185,7 @@ constructor(
if (player.currentMediaItem != null && player.currentMediaItem!!.mediaId.isNotEmpty()) {
val itemId = UUID.fromString(player.currentMediaItem!!.mediaId)
if (playFromDownloads) {
postDownloadPlaybackProgress(downloadDatabase, itemId, player.currentPosition, (player.currentPosition.toDouble() / player.duration.toDouble()).times(100)) // TODO Automatically use the correct item
postDownloadPlaybackProgress(downloadDatabase, items[0].itemId, player.currentPosition.times(10000), (player.currentPosition.toDouble() / player.duration.toDouble()).times(100)) // TODO Automatically use the correct item
}
try {
jellyfinRepository.postPlaybackProgress(