Merge pull request #7061 from FineFindus/fix/save-watch-position-on-playback-end

fix(player): save watch position on playback end
This commit is contained in:
Bnyro 2025-02-03 22:22:45 +01:00 committed by GitHub
commit 523a2879be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -68,9 +68,6 @@ object DatabaseHelper {
getWatchPosition(videoId)
}
fun isVideoWatchedBlocking(videoId: String, duration: Long) =
runBlocking { isVideoWatched(videoId, duration) }
suspend fun isVideoWatched(videoId: String, duration: Long): Boolean =
withContext(Dispatchers.IO) {
val position = getWatchPosition(videoId) ?: return@withContext false

View File

@ -94,8 +94,13 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
override fun onPlaybackStateChanged(playbackState: Int) {
super.onPlaybackStateChanged(playbackState)
if (playbackState == Player.STATE_READY) {
isTransitioning = false
when (playbackState) {
Player.STATE_ENDED -> {
exoPlayer?.let { PlayerHelper.saveWatchPosition(it, videoId) }
}
Player.STATE_READY -> {
isTransitioning = false
}
}
}
}