dev → main: Android UPnP/Sonos transport parity + server stream URL extension #79
+25
-19
@@ -29,25 +29,7 @@ suspend fun playPlaylistShuffled(
|
|||||||
player: PlayerController,
|
player: PlayerController,
|
||||||
onMessage: (String) -> Unit,
|
onMessage: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val detail = try {
|
val detail = fetchPlaylistDetail(playlist, repository, onMessage) ?: return
|
||||||
withTimeout(PLAYLIST_FETCH_TIMEOUT_MS) {
|
|
||||||
if (playlist.refreshable && playlist.systemVariant != null) {
|
|
||||||
repository.systemShuffle(playlist.systemVariant)
|
|
||||||
} else {
|
|
||||||
repository.refreshDetail(playlist.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (
|
|
||||||
@Suppress("SwallowedException") _: TimeoutCancellationException,
|
|
||||||
) {
|
|
||||||
onMessage("Couldn't load playlist - check your connection")
|
|
||||||
return
|
|
||||||
} catch (
|
|
||||||
@Suppress("TooGenericExceptionCaught") e: Throwable,
|
|
||||||
) {
|
|
||||||
onMessage("Couldn't load playlist: ${ErrorCopy.fromThrowable(e)}")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val tracks = detail.tracks.toPlayableTrackRefs()
|
val tracks = detail.tracks.toPlayableTrackRefs()
|
||||||
if (tracks.isEmpty()) {
|
if (tracks.isEmpty()) {
|
||||||
onMessage("Mix isn't ready yet - try again in a moment")
|
onMessage("Mix isn't ready yet - try again in a moment")
|
||||||
@@ -63,3 +45,27 @@ suspend fun playPlaylistShuffled(
|
|||||||
val ordered = if (playlist.isSystem) tracks.shuffled() else tracks
|
val ordered = if (playlist.isSystem) tracks.shuffled() else tracks
|
||||||
player.setQueue(ordered, initialIndex = 0, source = source)
|
player.setQueue(ordered, initialIndex = 0, source = source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun fetchPlaylistDetail(
|
||||||
|
playlist: PlaylistRef,
|
||||||
|
repository: PlaylistsRepository,
|
||||||
|
onMessage: (String) -> Unit,
|
||||||
|
): PlaylistDetailRef? = try {
|
||||||
|
withTimeout(PLAYLIST_FETCH_TIMEOUT_MS) {
|
||||||
|
if (playlist.refreshable && playlist.systemVariant != null) {
|
||||||
|
repository.systemShuffle(playlist.systemVariant)
|
||||||
|
} else {
|
||||||
|
repository.refreshDetail(playlist.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (
|
||||||
|
@Suppress("SwallowedException") _: TimeoutCancellationException,
|
||||||
|
) {
|
||||||
|
onMessage("Couldn't load playlist - check your connection")
|
||||||
|
null
|
||||||
|
} catch (
|
||||||
|
@Suppress("TooGenericExceptionCaught") e: Throwable,
|
||||||
|
) {
|
||||||
|
onMessage("Couldn't load playlist: ${ErrorCopy.fromThrowable(e)}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user