diff --git a/app/src/main/java/com/github/libretube/db/dao/DownloadDao.kt b/app/src/main/java/com/github/libretube/db/dao/DownloadDao.kt index e0d1e0dba..5882cc672 100644 --- a/app/src/main/java/com/github/libretube/db/dao/DownloadDao.kt +++ b/app/src/main/java/com/github/libretube/db/dao/DownloadDao.kt @@ -11,6 +11,7 @@ import com.github.libretube.db.obj.Download import com.github.libretube.db.obj.DownloadChapter import com.github.libretube.db.obj.DownloadItem import com.github.libretube.db.obj.DownloadWithItems +import com.github.libretube.enums.FileType @Dao interface DownloadDao { @@ -22,6 +23,9 @@ interface DownloadDao { @Query("SELECT * FROM download WHERE videoId = :videoId") suspend fun findById(videoId: String): DownloadWithItems + @Query("SELECT videoId FROM downloadItem WHERE type = :fileType ORDER BY RANDOM() LIMIT 1") + suspend fun getRandomVideoIdByFileType(fileType: FileType): String? + @Query("SELECT * FROM downloaditem WHERE id = :id") suspend fun findDownloadItemById(id: Int): DownloadItem? diff --git a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt index 9c61ac355..7772704b3 100644 --- a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt @@ -42,8 +42,7 @@ class OfflinePlayerService : AbstractPlayerService() { videoId = if (shuffle) { runBlocking(Dispatchers.IO) { - Database.downloadDao().getAll().filterByTab(downloadTab) - .randomOrNull()?.download?.videoId + Database.downloadDao().getRandomVideoIdByFileType(FileType.AUDIO) } } else { intent.getStringExtra(IntentData.videoId)