fix the watch position pref

This commit is contained in:
Bnyro 2022-11-21 15:34:43 +01:00
parent 0ac61168cf
commit 7c3780137d
2 changed files with 15 additions and 14 deletions

View File

@ -131,7 +131,7 @@ class BackgroundMode : Service() {
streamItem.url?.toID()?.let { playNextVideo(it) }
}
updateWatchPosition()
if (PlayerHelper.watchPositionsEnabled) updateWatchPosition()
} catch (e: Exception) {
onDestroy()
}

View File

@ -501,11 +501,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
override fun onDestroy() {
super.onDestroy()
try {
// clear the playing queue
PlayingQueue.resetToDefaults()
saveWatchPosition()
// clear the playing queue and release the player
PlayingQueue.resetToDefaults()
nowPlayingNotification.destroySelfAndPlayer()
activity?.requestedOrientation =
if ((activity as MainActivity).autoRotationEnabled) {
ActivityInfo.SCREEN_ORIENTATION_USER
@ -520,17 +521,17 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
// save the watch position if video isn't finished and option enabled
private fun saveWatchPosition() {
if (!PlayerHelper.watchPositionsEnabled) return
if (exoPlayer.currentPosition != exoPlayer.duration) {
Log.e(
"watchpositions",
PreferenceHelper.getBoolean(
PreferenceKeys.WATCH_POSITION_TOGGLE,
true
).toString()
)
val watchPosition = WatchPosition(videoId!!, exoPlayer.currentPosition)
query {
Database.watchPositionDao().insertAll(watchPosition)
}
} else if (PlayerHelper.watchPositionsEnabled) {
// delete watch position if video has ended
query {
Database.watchPositionDao().deleteById(videoId!!)
}
}
}
private fun checkForSegments() {