mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 13:50:30 +05:30
fix: clearing watch positions doesn't works sometimes (#5557)
This commit is contained in:
parent
3f391c3795
commit
9fc80a2877
@ -48,7 +48,6 @@ import androidx.media3.exoplayer.ExoPlayer
|
|||||||
import androidx.media3.exoplayer.hls.HlsMediaSource
|
import androidx.media3.exoplayer.hls.HlsMediaSource
|
||||||
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
|
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.github.libretube.NavDirections
|
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.CronetHelper
|
import com.github.libretube.api.CronetHelper
|
||||||
import com.github.libretube.api.JsonHelper
|
import com.github.libretube.api.JsonHelper
|
||||||
@ -252,6 +251,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// schedule task to save the watch position each second
|
||||||
|
private var watchPositionTimer: Timer? = null
|
||||||
|
|
||||||
private val playerListener = object : Player.Listener {
|
private val playerListener = object : Player.Listener {
|
||||||
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||||
if (PlayerHelper.pipEnabled) {
|
if (PlayerHelper.pipEnabled) {
|
||||||
@ -276,6 +278,18 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
100
|
100
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start or pause watch position timer
|
||||||
|
if (isPlaying) {
|
||||||
|
watchPositionTimer = Timer()
|
||||||
|
watchPositionTimer!!.scheduleAtFixedRate(object : TimerTask() {
|
||||||
|
override fun run() {
|
||||||
|
handler.post(this@PlayerFragment::saveWatchPosition)
|
||||||
|
}
|
||||||
|
}, 1000, 1000)
|
||||||
|
} else {
|
||||||
|
watchPositionTimer?.cancel()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onEvents(player: Player, events: Player.Events) {
|
override fun onEvents(player: Player, events: Player.Events) {
|
||||||
@ -366,17 +380,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
IntentFilter(PlayerHelper.getIntentAction(requireContext()))
|
IntentFilter(PlayerHelper.getIntentAction(requireContext()))
|
||||||
)
|
)
|
||||||
|
|
||||||
// schedule task to save the watch position each second
|
|
||||||
Timer().scheduleAtFixedRate(
|
|
||||||
object : TimerTask() {
|
|
||||||
override fun run() {
|
|
||||||
handler.post(this@PlayerFragment::saveWatchPosition)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
1000,
|
|
||||||
1000
|
|
||||||
)
|
|
||||||
|
|
||||||
fullscreenResolution = PlayerHelper.getDefaultResolution(requireContext(), true)
|
fullscreenResolution = PlayerHelper.getDefaultResolution(requireContext(), true)
|
||||||
noFullscreenResolution = PlayerHelper.getDefaultResolution(requireContext(), false)
|
noFullscreenResolution = PlayerHelper.getDefaultResolution(requireContext(), false)
|
||||||
}
|
}
|
||||||
@ -820,6 +823,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
_binding = null
|
_binding = null
|
||||||
|
|
||||||
stopVideoPlay()
|
stopVideoPlay()
|
||||||
|
|
||||||
|
watchPositionTimer?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopVideoPlay() {
|
private fun stopVideoPlay() {
|
||||||
|
Loading…
Reference in New Issue
Block a user