From 485cc190237f68fd852b117854dcc8fd9b7a51e2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 19 Sep 2022 21:52:08 +0200 Subject: [PATCH] fix crash when videoId null --- .../main/java/com/github/libretube/db/dao/WatchPositionDao.kt | 2 +- .../java/com/github/libretube/fragments/PlayerFragment.kt | 3 ++- app/src/main/java/com/github/libretube/util/PlayingQueue.kt | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/db/dao/WatchPositionDao.kt b/app/src/main/java/com/github/libretube/db/dao/WatchPositionDao.kt index 09ec247ac..6855eaab4 100644 --- a/app/src/main/java/com/github/libretube/db/dao/WatchPositionDao.kt +++ b/app/src/main/java/com/github/libretube/db/dao/WatchPositionDao.kt @@ -13,7 +13,7 @@ interface WatchPositionDao { fun getAll(): List @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) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index daea985dd..41534f0d5 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -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) { diff --git a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt index 181d47588..ecc5d6e9d 100644 --- a/app/src/main/java/com/github/libretube/util/PlayingQueue.kt +++ b/app/src/main/java/com/github/libretube/util/PlayingQueue.kt @@ -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() 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 {