Skip to content

Commit

Permalink
wrap as much as pissible in update{} in NewPlayerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 23, 2024
1 parent 345fd37 commit 88d3bf0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 26 additions & 23 deletions new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,20 @@ class NewPlayerImpl(
@OptIn(UnstableApi::class)
override fun onTracksChanged(tracks: Tracks) {
super.onTracksChanged(tracks)
val streamTracks =
TrackUtils.streamTracksFromMedia3Tracks(tracks, onlySelectedTracks = true)
.ifEmpty {
TrackUtils.streamTracksFromMedia3Tracks(
tracks,
onlySelectedTracks = false
)
}
streamTracks.joinToString("\n") { it.toString() }
Log.d(
TAG,
"currently playing tracks: \n ${streamTracks.joinToString("\n") { it.toString() }}"
)
mutableCurrentlyPlayingTracks.update {
val streamTracks =
TrackUtils.streamTracksFromMedia3Tracks(tracks, onlySelectedTracks = true)
.ifEmpty {
TrackUtils.streamTracksFromMedia3Tracks(
tracks,
onlySelectedTracks = false
)
}
Log.d(
TAG,
"currently playing tracks: \n ${streamTracks.joinToString("\n") { it.toString() }}"
)

streamTracks
}
}
Expand Down Expand Up @@ -304,16 +304,19 @@ class NewPlayerImpl(
init {
playerScope.launch {
currentlyPlaying.collect { playing ->
playing?.let {
try {
val chapters =
repository.getChapters(
uniqueIdToStreamSelectionLookup[playing.mediaId.toLong()]!!.item
)
mutableCurrentChapter.update { chapters }
} catch (e: Exception) {
mutableErrorFlow.emit(e)
}
mutableCurrentChapter.update {
playing?.let {
try {
val chapters =
repository.getChapters(
uniqueIdToStreamSelectionLookup[playing.mediaId.toLong()]!!.item
)
return@let chapters
} catch (e: Exception) {
mutableErrorFlow.emit(e)
return@let emptyList()
}
} ?: emptyList()
}
}
}
Expand Down

0 comments on commit 88d3bf0

Please sign in to comment.