From b4d7a9b8a5688c8555223e62aad77a5ea7a452db Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sat, 1 Feb 2025 09:22:23 +0100 Subject: [PATCH 1/2] refactor(DatabaseHelper): cleanup unused function --- app/src/main/java/com/github/libretube/db/DatabaseHelper.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt index 71543ffb9..20704325a 100644 --- a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt +++ b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt @@ -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 From 2a2ad88655d543b57714bb19d08a5db4f191f7b5 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sat, 1 Feb 2025 09:24:51 +0100 Subject: [PATCH 2/2] fix(Player): save watch position when playback ends This fixes an issue, where the watch position would not correctly be saved as the fully watched video. This could occur when the last part of a video was skipped by a sponsorblock segment. --- .../github/libretube/services/AbstractPlayerService.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt b/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt index 7b3c5655e..9e9bb03c9 100644 --- a/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt @@ -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 + } } } }