mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-24 03:36:51 +00:00
feat: enhance media playback handling with offline support and download metadata integration
This commit is contained in:
@@ -68,8 +68,8 @@ class CompositeLocalMediaRepository @Inject constructor(
|
||||
}
|
||||
|
||||
override suspend fun updateWatchProgress(mediaId: UUID, positionMs: Long, durationMs: Long) {
|
||||
val repository = onlineRepository
|
||||
repository.updateWatchProgress(mediaId, positionMs, durationMs)
|
||||
onlineRepository.updateWatchProgress(mediaId, positionMs, durationMs)
|
||||
offlineRepository.updateWatchProgress(mediaId, positionMs, durationMs)
|
||||
}
|
||||
|
||||
override suspend fun markAsWatched(mediaId: UUID, watched: Boolean) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package hu.bbara.purefin.core.download
|
||||
|
||||
import androidx.media3.common.MediaItem
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.util.UUID
|
||||
@@ -7,6 +8,7 @@ import java.util.UUID
|
||||
interface MediaDownloadController {
|
||||
fun observeActiveDownloads(): Flow<Map<String, Float>>
|
||||
fun observeDownloadState(contentId: String): StateFlow<DownloadState>
|
||||
fun getCompletedDownloadMediaItem(contentId: String): MediaItem?
|
||||
suspend fun downloadMovie(movieId: UUID)
|
||||
suspend fun cancelDownload(movieId: UUID)
|
||||
suspend fun downloadEpisode(episodeId: UUID)
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.core.net.toUri
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.exoplayer.offline.Download
|
||||
import androidx.media3.exoplayer.offline.DownloadManager
|
||||
@@ -109,6 +110,12 @@ class MediaDownloadManager @Inject constructor(
|
||||
return downloadManager.downloadIndex.getDownload(contentId)?.state == Download.STATE_COMPLETED
|
||||
}
|
||||
|
||||
override fun getCompletedDownloadMediaItem(contentId: String): MediaItem? {
|
||||
val download = downloadManager.downloadIndex.getDownload(contentId) ?: return null
|
||||
if (download.state != Download.STATE_COMPLETED) return null
|
||||
return download.request.toMediaItem()
|
||||
}
|
||||
|
||||
override suspend fun downloadMovie(movieId: UUID) {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user