Merge pull request #2999 from Bnyro/master

Fix the time stamp parsing in the `PlayerFragment`
This commit is contained in:
Bnyro 2023-02-08 10:38:46 +01:00 committed by GitHub
commit bd88a5a81b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -121,7 +121,7 @@ class AudioPlayerFragment : BaseFragment(), AudioPlayerOptions {
NavigationHelper.navigateVideo(
context = requireContext(),
videoId = PlayingQueue.getCurrent()?.url?.toID(),
timeStamp = playerService?.player?.currentPosition,
timeStamp = playerService?.player?.currentPosition?.div(1000),
keepQueue = true,
forceVideo = true
)

View File

@ -141,6 +141,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
private var playlistId: String? = null
private var channelId: String? = null
private var keepQueue: Boolean = false
private var timeStamp: Long? = null
/**
* Video information fetched at runtime
@ -228,6 +229,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
playlistId = it.getString(IntentData.playlistId)
channelId = it.getString(IntentData.channelId)
keepQueue = it.getBoolean(IntentData.keepQueue, false)
timeStamp = it.getLong(IntentData.timeStamp, 0L)
}
// broadcast receiver for PiP actions
@ -716,6 +718,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
setupSeekbarPreview()
if (!streams.livestream) seekToWatchPosition()
trySeekToTimeStamp()
exoPlayer.prepare()
if (!DataSaverMode.isEnabled(requireContext())) exoPlayer.play()
@ -786,14 +790,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
handler.postDelayed(this@PlayerFragment::refreshLiveStatus, 100)
}
// seek to saved watch position if available
/**
* Seek to saved watch position if available */
private fun seekToWatchPosition() {
// support for time stamped links
val timeStamp: Long? = arguments?.getLong(IntentData.timeStamp)
if (timeStamp != null && timeStamp != 0L) {
exoPlayer.seekTo(timeStamp * 1000)
return
}
// browse the watch positions
val position = try {
awaitQuery {
@ -808,6 +807,18 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
}
}
/**
* Seek to the time stamp passed by the intent arguments if available
*/
private fun trySeekToTimeStamp() {
// support for time stamped links
timeStamp?.let {
if (it != 0L) exoPlayer.seekTo(it * 1000)
}
// delete the time stamp because it already got consumed
timeStamp = null
}
// used for autoplay and skipping to next video
private fun playNextVideo(nextId: String? = null) {
val nextVideoId = nextId ?: PlayingQueue.getNext()