Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix player stops when next urn item fails to load. #251

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import androidx.media3.exoplayer.upstream.Allocator
import ch.srgssr.pillarbox.player.data.MediaItemSource
import ch.srgssr.pillarbox.player.source.PillarboxMediaSource.PillarboxTimeline.Companion.LIVE_DVR_MIN_DURATION_MS
import ch.srgssr.pillarbox.player.utils.DebugLogger
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.runBlocking

/**
Expand All @@ -33,21 +32,24 @@ class PillarboxMediaSource(
) : CompositeMediaSource<String>() {
private var loadedMediaSource: MediaSource? = null
private var pendingError: Throwable? = null
private val exceptionHandler = CoroutineExceptionHandler { _, exception ->
handleException(exception)
}

@Suppress("TooGenericExceptionCaught")
override fun prepareSourceInternal(mediaTransferListener: TransferListener?) {
super.prepareSourceInternal(mediaTransferListener)
DebugLogger.debug(TAG, "prepareSourceInternal: mediaId = ${mediaItem.mediaId} on ${Thread.currentThread()}")
pendingError = null
runBlocking(exceptionHandler) {
val loadedItem = mediaItemSource.loadMediaItem(mediaItem)
mediaItem = loadedItem
loadedMediaSource = mediaSourceFactory.createMediaSource(loadedItem)
loadedMediaSource?.let {
DebugLogger.debug(TAG, "prepare child source loaded mediaId = ${loadedItem.mediaId}")
prepareChildSource(loadedItem.mediaId, it)
// We have to use runBlocking to execute code in the same thread as prepareSourceInternal due to DRM.
runBlocking {
try {
val loadedItem = mediaItemSource.loadMediaItem(mediaItem)
mediaItem = loadedItem
loadedMediaSource = mediaSourceFactory.createMediaSource(loadedItem)
loadedMediaSource?.let {
DebugLogger.debug(TAG, "prepare child source loaded mediaId = ${loadedItem.mediaId}")
prepareChildSource(loadedItem.mediaId, it)
}
} catch (e: Exception) {
handleException(e)
}
}
}
Expand Down