This commit is contained in:
Bnyro 2022-08-21 10:15:37 +02:00
parent 676d356dca
commit db77d96764
2 changed files with 19 additions and 3 deletions

View File

@ -907,7 +907,7 @@ class PlayerFragment : BaseFragment() {
if (!this::autoPlayHelper.isInitialized) autoPlayHelper = AutoPlayHelper(playlistId)
// search for the next videoId in the playlist
lifecycleScope.launchWhenCreated {
nextStreamId = autoPlayHelper.getNextVideoId(videoId!!, streams.relatedStreams!!)
nextStreamId = autoPlayHelper.getNextVideoId(videoId!!, streams.relatedStreams)
}
}

View File

@ -13,9 +13,12 @@ class AutoPlayHelper(
private val playlistStreamIds = mutableListOf<String>()
private var playlistNextPage: String? = null
/**
* get the id of the next video to be played
*/
suspend fun getNextVideoId(
currentVideoId: String,
relatedStreams: List<StreamItem>
relatedStreams: List<StreamItem>?
): String? {
return if (Globals.playingQueue.last() != currentVideoId) {
val currentVideoIndex = Globals.playingQueue.indexOf(currentVideoId)
@ -28,8 +31,15 @@ class AutoPlayHelper(
)
}
private fun getNextTrendingVideoId(videoId: String, relatedStreams: List<StreamItem>): String? {
/**
* get the id of the next related video
*/
private fun getNextTrendingVideoId(
videoId: String,
relatedStreams: List<StreamItem>?
): String? {
// don't play a video if it got played before already
if (relatedStreams == null || relatedStreams.isEmpty()) return null
var index = 0
var nextStreamId: String? = null
while (nextStreamId == null ||
@ -47,6 +57,9 @@ class AutoPlayHelper(
return nextStreamId
}
/**
* get the videoId of the next video in a playlist
*/
private suspend fun getNextPlaylistVideoId(currentVideoId: String): String? {
// if the playlists contain the video, then save the next video as next stream
if (playlistStreamIds.contains(currentVideoId)) {
@ -76,6 +89,9 @@ class AutoPlayHelper(
return null
}
/**
* get the videoId of the next video in the playing queue
*/
fun getNextPlayingQueueVideoId(
currentVideoId: String
): String? {