improve live video handling

This commit is contained in:
Bnyro 2022-07-30 15:54:47 +02:00
parent c777560e54
commit aa4817f0a8

View File

@ -770,12 +770,6 @@ class PlayerFragment : Fragment() {
// save related streams for autoplay // save related streams for autoplay
relatedStreams = response.relatedStreams relatedStreams = response.relatedStreams
// duration that's not greater than 0 indicates that the video is live
if (!(response.duration!! > 0)) {
isLive = true
handleLiveVideo()
}
runOnUiThread { runOnUiThread {
// set media sources for the player // set media sources for the player
setResolutionAndSubtitles(response) setResolutionAndSubtitles(response)
@ -800,21 +794,14 @@ class PlayerFragment : Fragment() {
run() run()
} }
private fun handleLiveVideo() {
playerBinding.exoTime.visibility = View.GONE
playerBinding.liveLL.visibility = View.VISIBLE
refreshLiveStatus()
}
private fun refreshLiveStatus() { private fun refreshLiveStatus() {
// switch back to normal speed when on the end of live stream // switch back to normal speed when on the end of live stream
Log.e(exoPlayer.duration.toString(), exoPlayer.currentPosition.toString()) if (exoPlayer.duration - exoPlayer.currentPosition < 7000) {
if (isLive && (exoPlayer.duration - exoPlayer.currentPosition < 10000)) {
exoPlayer.setPlaybackSpeed(1F) exoPlayer.setPlaybackSpeed(1F)
playerBinding.speedText.text = "1x" playerBinding.speedText.text = "1x"
playerBinding.liveSeparator.visibility = View.GONE playerBinding.liveSeparator.visibility = View.GONE
playerBinding.liveDiff.text = "" playerBinding.liveDiff.text = ""
} else if (isLive) { } else {
Log.e(TAG, "changing the time") Log.e(TAG, "changing the time")
// live stream but not watching at the end/live position // live stream but not watching at the end/live position
playerBinding.liveSeparator.visibility = View.VISIBLE playerBinding.liveSeparator.visibility = View.VISIBLE
@ -977,6 +964,15 @@ class PlayerFragment : Fragment() {
} }
} }
private fun handleLiveVideo() {
playerBinding.exoTime.visibility = View.GONE
playerBinding.liveLL.visibility = View.VISIBLE
playerBinding.liveIndicator.setOnClickListener {
exoPlayer.seekTo(exoPlayer.duration - 1000)
}
refreshLiveStatus()
}
private fun initializePlayerView(response: Streams) { private fun initializePlayerView(response: Streams) {
binding.apply { binding.apply {
playerViewsInfo.text = playerViewsInfo.text =
@ -994,6 +990,12 @@ class PlayerFragment : Fragment() {
playerDescription.text = response.description playerDescription.text = response.description
} }
// duration that's not greater than 0 indicates that the video is live
if (!(response.duration!! > 0)) {
isLive = true
handleLiveVideo()
}
playerBinding.exoTitle.text = response.title playerBinding.exoTitle.text = response.title
if (seekBarPreview) enableSeekbarPreview() if (seekBarPreview) enableSeekbarPreview()