fix crash when videoId null

This commit is contained in:
Bnyro 2022-09-19 21:52:08 +02:00
parent c835f5ab80
commit 485cc19023
3 changed files with 7 additions and 2 deletions

View File

@ -13,7 +13,7 @@ interface WatchPositionDao {
fun getAll(): List<WatchPosition>
@Query("SELECT * FROM watchPosition WHERE videoId LIKE :videoId LIMIT 1")
fun findById(videoId: String): WatchPosition
fun findById(videoId: String): WatchPosition?
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(vararg watchPositions: WatchPosition)

View File

@ -866,7 +866,8 @@ class PlayerFragment : BaseFragment() {
var position: Long? = null
Thread {
try {
position = Database.watchPositionDao().findById(videoId!!).position
val watchPosition = Database.watchPositionDao().findById(videoId!!)
position = if (watchPosition != null) watchPosition.position else null
// 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

@ -1,5 +1,8 @@
package com.github.libretube.util
import android.util.Log
import com.github.libretube.extensions.TAG
object PlayingQueue {
private val queue = mutableListOf<String>()
private var currentVideoId: String? = null
@ -21,6 +24,7 @@ object PlayingQueue {
fun getNext(): String? {
val currentIndex = queue.indexOf(currentVideoId)
Log.e(TAG(), queue.toString())
return if (currentIndex > queue.size) {
null
} else {