This commit is contained in:
Bnyro 2022-09-19 22:21:30 +02:00
parent 7844cc7792
commit 658a6648ff
3 changed files with 10 additions and 11 deletions

View File

@ -757,8 +757,9 @@ class PlayerFragment : BaseFragment() {
}
private fun playVideo() {
PlayingQueue.updateCurrent(videoId!!)
lifecycleScope.launchWhenCreated {
PlayingQueue.updateCurrent(videoId!!)
streams = try {
RetrofitInstance.api.getStreams(videoId!!)
} catch (e: IOException) {
@ -866,8 +867,7 @@ class PlayerFragment : BaseFragment() {
var position: Long? = null
Thread {
try {
val watchPosition = Database.watchPositionDao().findById(videoId!!)
position = if (watchPosition != null) watchPosition.position else null
position = Database.watchPositionDao().findById(videoId!!)?.position
// position is almost the end of the video => don't seek, start from beginning
if (position!! > streams.duration!! * 1000 * 0.9) position = null
} catch (e: Exception) {

View File

@ -37,8 +37,9 @@ class VideoOptionsBottomSheet(
)
}
/**
* Check whether the player is running by observing the notification
* Check whether the player is running and add queue options
*/
if (PlayingQueue.isNotEmpty()) {
optionsList += context?.getString(R.string.play_next)!!

View File

@ -32,15 +32,13 @@ object PlayingQueue {
}
}
fun getPrev(): String {
return queue[
queue.indexOf(currentVideoId) - 1
]
fun getPrev(): String? {
val index = queue.indexOf(currentVideoId)
return if (index > 0) queue[index - 1] else null
}
fun hasPrev(): Boolean {
val currentIndex = queue.indexOf(currentVideoId)
return queue.size > currentIndex + 1
return queue.indexOf(currentVideoId) > 0
}
fun contains(videoId: String): Boolean {
@ -53,7 +51,7 @@ object PlayingQueue {
fun updateCurrent(videoId: String) {
currentVideoId = videoId
if (!contains(videoId)) add(videoId)
queue.add(videoId)
}
fun isNotEmpty() = queue.isNotEmpty()