Skip to content

Commit

Permalink
Merge pull request #7061 from FineFindus/fix/save-watch-position-on-p…
Browse files Browse the repository at this point in the history
…layback-end

fix(player): save watch position on playback end
  • Loading branch information
Bnyro authored Feb 3, 2025
2 parents 6c0ac68 + 2a2ad88 commit 523a287
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 0 additions & 3 deletions app/src/main/java/com/github/libretube/db/DatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit 523a287

Please sign in to comment.