Skip to content

Commit

Permalink
remove language identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 16, 2024
1 parent ac16514 commit e14a599
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 1,399 deletions.
6 changes: 3 additions & 3 deletions new-player/src/main/java/net/newpipe/newplayer/NewPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import net.newpipe.newplayer.data.Chapter
import net.newpipe.newplayer.data.LanguageIdentifier
import net.newpipe.newplayer.data.Stream
import net.newpipe.newplayer.data.StreamSelection
import net.newpipe.newplayer.data.StreamTrack
import kotlin.Exception

Expand All @@ -52,7 +52,7 @@ enum class RepeatMode {

interface NewPlayer {
// preferences
var preferredStreamLanguages: List<LanguageIdentifier>
var preferredStreamLanguages: List<String>
val notificationIcon: IconCompat
val playerActivityClass: Class<Activity>

Expand All @@ -73,7 +73,7 @@ interface NewPlayer {

val currentChapters: StateFlow<List<Chapter>>

val currentlyPlayingStream: StateFlow<Stream?>
val currentlyPlayingTracks: StateFlow<List<StreamTrack>>
val currentlyAvailableTracks: StateFlow<List<StreamTrack>>

// callbacks
Expand Down
37 changes: 10 additions & 27 deletions new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import kotlinx.coroutines.launch
import net.newpipe.newplayer.service.NewPlayerService
import net.newpipe.newplayer.logic.ActionResponse
import net.newpipe.newplayer.data.Chapter
import net.newpipe.newplayer.data.LanguageIdentifier
import net.newpipe.newplayer.logic.MediaSourceBuilder
import net.newpipe.newplayer.data.NewPlayerException
import net.newpipe.newplayer.logic.NoResponse
Expand Down Expand Up @@ -88,7 +87,10 @@ class NewPlayerImpl(
override val exoPlayer = mutableExoPlayer.asStateFlow()


override var preferredStreamLanguages: List<LanguageIdentifier> = emptyList()
/**
* Must be in IETF-BCP-47 format
*/
override var preferredStreamLanguages: List<String> = emptyList()

private var playerScope = CoroutineScope(Dispatchers.Main + Job())

Expand Down Expand Up @@ -170,8 +172,8 @@ class NewPlayerImpl(
private var mutableCurrentlyAvailableTracks = MutableStateFlow<List<StreamTrack>>(emptyList())
override val currentlyAvailableTracks: StateFlow<List<StreamTrack>> = mutableCurrentlyAvailableTracks.asStateFlow()

private var mutableCurrentlyPlayingStream = MutableStateFlow<Stream?>(null)
override val currentlyPlayingStream = mutableCurrentlyPlayingStream.asStateFlow()
private var mutableCurrentlyPlayingTracks = MutableStateFlow<List<StreamTrack>>(emptyList())
override val currentlyPlayingTracks: StateFlow<List<StreamTrack>> = mutableCurrentlyPlayingTracks.asStateFlow()

private fun setupNewExoplayer() {
val newExoPlayer = ExoPlayer.Builder(app)
Expand Down Expand Up @@ -213,14 +215,15 @@ class NewPlayerImpl(
}
} else {
mutableCurrentlyAvailableTracks.update { emptyList() }
mutableCurrentlyPlayingStream.update { null }
}
}

@OptIn(UnstableApi::class)
override fun onTracksChanged(tracks: Tracks) {
super.onTracksChanged(tracks)
updateStreamSelection()
mutableCurrentlyPlayingTracks.update {
TrackUtils.streamTracksFromMedia3Tracks(tracks, onlySelectedTracks = true)
}
}
})
mutableExoPlayer.update {
Expand Down Expand Up @@ -353,26 +356,6 @@ class NewPlayerImpl(
}
}


@OptIn(UnstableApi::class)
private fun updateStreamSelection() {
currentlyPlaying.value?.let { mediaItem ->

exoPlayer.value?.currentTracks?.let { tracks ->
println("gurken trackgroups : ${tracks.groups.size}")
var group_num = 0
for (group in tracks.groups) {
println(" gurken group: ${++group_num}")
for (i in 0 until group.length) {
val format = group.getTrackFormat(i)
format.metadata
println(" gurken track $i: language: ${format.language}, labels: ${format.labels.size}, width: ${format.width} height: ${format.height}")
}
}
}
}
}

@OptIn(UnstableApi::class)
override fun selectChapter(index: Int) {
val chapters = currentChapters.value
Expand All @@ -394,7 +377,7 @@ class NewPlayerImpl(
}
mediaController = null
mutableCurrentlyAvailableTracks.update { emptyList() }
mutableCurrentlyPlayingStream.update { null }
mutableCurrentlyPlayingTracks.update { emptyList() }
uniqueIdToStreamSelectionLookup = HashMap()
}

Expand Down
Loading

0 comments on commit e14a599

Please sign in to comment.