fix repeating videos

This commit is contained in:
Bnyro 2022-08-08 17:24:46 +02:00
parent b0ca6baafd
commit 0b2f63c4f5

View File

@ -577,8 +577,6 @@ class PlayerFragment : BaseFragment() {
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
playerBinding.exoTitle.visibility = View.VISIBLE playerBinding.exoTitle.visibility = View.VISIBLE
scaleControls(1.3F)
val mainActivity = activity as MainActivity val mainActivity = activity as MainActivity
if (!autoRotationEnabled) { if (!autoRotationEnabled) {
// different orientations of the video are only available when auto rotation is disabled // different orientations of the video are only available when auto rotation is disabled
@ -613,8 +611,6 @@ class PlayerFragment : BaseFragment() {
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen) playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
playerBinding.exoTitle.visibility = View.INVISIBLE playerBinding.exoTitle.visibility = View.INVISIBLE
scaleControls(1F)
if (!autoRotationEnabled) { if (!autoRotationEnabled) {
// switch back to portrait mode if auto rotation disabled // switch back to portrait mode if auto rotation disabled
val mainActivity = activity as MainActivity val mainActivity = activity as MainActivity
@ -624,11 +620,6 @@ class PlayerFragment : BaseFragment() {
Globals.IS_FULL_SCREEN = false Globals.IS_FULL_SCREEN = false
} }
private fun scaleControls(scaleFactor: Float) {
playerBinding.exoPlayPause.scaleX = scaleFactor
playerBinding.exoPlayPause.scaleY = scaleFactor
}
private fun toggleDescription() { private fun toggleDescription() {
if (binding.descLinLayout.isVisible) { if (binding.descLinLayout.isVisible) {
// hide the description and chapters // hide the description and chapters
@ -766,7 +757,18 @@ class PlayerFragment : BaseFragment() {
* set the videoId of the next stream for autoplay * set the videoId of the next stream for autoplay
*/ */
private fun setNextStream() { private fun setNextStream() {
nextStreamId = streams.relatedStreams!![0].url.toID() // don't play a video if it got played before already
var index = 0
while (nextStreamId == null || nextStreamId == videoId!! ||
(
videoIds.contains(nextStreamId) &&
videoIds.indexOf(videoId) > videoIds.indexOf(nextStreamId)
)
) {
nextStreamId = streams.relatedStreams!![index].url.toID()
if (index + 1 < streams.relatedStreams!!.size) index += 1
else break
}
if (playlistId == null) return if (playlistId == null) return
if (!this::autoPlayHelper.isInitialized) autoPlayHelper = AutoPlayHelper(playlistId!!) if (!this::autoPlayHelper.isInitialized) autoPlayHelper = AutoPlayHelper(playlistId!!)
// search for the next videoId in the playlist // search for the next videoId in the playlist
@ -835,17 +837,16 @@ class PlayerFragment : BaseFragment() {
// used for autoplay and skipping to next video // used for autoplay and skipping to next video
private fun playNextVideo() { private fun playNextVideo() {
if (nextStreamId == null) return
// check whether there is a new video in the queue // check whether there is a new video in the queue
// by making sure that the next and the current video aren't the same // by making sure that the next and the current video aren't the same
saveWatchPosition() saveWatchPosition()
// forces the comments to reload for the new video // forces the comments to reload for the new video
commentsLoaded = false commentsLoaded = false
binding.commentsRecView.adapter = null binding.commentsRecView.adapter = null
if (videoId != nextStreamId) { // save the id of the next stream as videoId and load the next video
// save the id of the next stream as videoId and load the next video videoId = nextStreamId
videoId = nextStreamId playVideo()
playVideo()
}
} }
private fun prepareExoPlayerView() { private fun prepareExoPlayerView() {