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) } streamItem.url?.toID()?.let { playNextVideo(it) }
} }
updateWatchPosition() if (PlayerHelper.watchPositionsEnabled) updateWatchPosition()
} catch (e: Exception) { } catch (e: Exception) {
onDestroy() onDestroy()
} }

View File

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