postpone trackselectoin for now
This commit is contained in:
parent
120ecae3c0
commit
7dbe166484
|
@ -30,6 +30,7 @@ import androidx.media3.common.MediaItem
|
||||||
import androidx.media3.common.PlaybackException
|
import androidx.media3.common.PlaybackException
|
||||||
import androidx.media3.common.Player
|
import androidx.media3.common.Player
|
||||||
import androidx.media3.common.Timeline
|
import androidx.media3.common.Timeline
|
||||||
|
import androidx.media3.common.Tracks
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
import androidx.media3.datasource.DefaultHttpDataSource
|
import androidx.media3.datasource.DefaultHttpDataSource
|
||||||
import androidx.media3.datasource.HttpDataSource
|
import androidx.media3.datasource.HttpDataSource
|
||||||
|
@ -196,11 +197,16 @@ class NewPlayerImpl(
|
||||||
if (mediaItem != null) {
|
if (mediaItem != null) {
|
||||||
val item = uniqueIdToIdLookup[mediaItem.mediaId.toLong()]!!
|
val item = uniqueIdToIdLookup[mediaItem.mediaId.toLong()]!!
|
||||||
updateStreamVariants(item)
|
updateStreamVariants(item)
|
||||||
updateStreamSelection(mediaItem)
|
|
||||||
} else {
|
} else {
|
||||||
mutableAvailableStreamVariants.update { null }
|
mutableAvailableStreamVariants.update { null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(UnstableApi::class)
|
||||||
|
override fun onTracksChanged(tracks: Tracks) {
|
||||||
|
super.onTracksChanged(tracks)
|
||||||
|
updateStreamSelection()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
mutableExoPlayer.update {
|
mutableExoPlayer.update {
|
||||||
newExoPlayer
|
newExoPlayer
|
||||||
|
@ -282,7 +288,6 @@ class NewPlayerImpl(
|
||||||
override fun playStream(item: String, playMode: PlayMode) {
|
override fun playStream(item: String, playMode: PlayMode) {
|
||||||
launchJobAndCollectError {
|
launchJobAndCollectError {
|
||||||
val mediaSource = toMediaSource(item)
|
val mediaSource = toMediaSource(item)
|
||||||
updateStreamSelection(mediaSource.mediaItem)
|
|
||||||
internalPlayStream(mediaSource, playMode)
|
internalPlayStream(mediaSource, playMode)
|
||||||
}
|
}
|
||||||
updateStreamVariants(item)
|
updateStreamVariants(item)
|
||||||
|
@ -300,21 +305,44 @@ class NewPlayerImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateStreamSelection(mediaItem: MediaItem) {
|
@OptIn(UnstableApi::class)
|
||||||
val selection = uniqueIdToStreamVariantSelection[mediaItem.mediaId.toLong()]
|
private fun updateStreamSelection() {
|
||||||
when (selection) {
|
// TODO: Track and Stream selection is not working right now.
|
||||||
is StreamSelector.SingleSelection -> {
|
// TIP: If you work on this try to find a way to only do track selection.
|
||||||
if (selection.stream.streamType != StreamType.DYNAMIC) {
|
// Stream selection is horrible code and must be done manually, while track selection
|
||||||
mutableCurrentlySelectedLanguage.update { selection.stream.language }
|
// can be offloaded to exoplayer.
|
||||||
mutableCurrentlySelectedStreamVariant.update { selection.stream.identifier }
|
// Now Track selection is the only way to go for DASH/HLS and Progressive Streams,
|
||||||
|
// but if you have a MergingMediaSource it is kind of tricky. The problem here:
|
||||||
|
// If you have multiple audio streams in your MergingMediaSource,
|
||||||
|
// and the streams are all marked to be "English" (The same language) you can only select
|
||||||
|
// each individual stream as stream, but when represented as track within a
|
||||||
|
// MergingMediaSource, you have no chance to select each individual track by language.
|
||||||
|
// Maybe this will change later on when ExoPlayer/Media3 is getting developed further on,
|
||||||
|
// or you will find another way to map each individual track to the stream it originates from.
|
||||||
|
currentlyPlaying.value?.let { mediaItem ->
|
||||||
|
val selection = uniqueIdToStreamVariantSelection[mediaItem.mediaId.toLong()]
|
||||||
|
when (selection) {
|
||||||
|
is StreamSelector.SingleSelection -> {
|
||||||
|
if (selection.stream.streamType != StreamType.DYNAMIC) {
|
||||||
|
mutableCurrentlySelectedLanguage.update { selection.stream.language }
|
||||||
|
mutableCurrentlySelectedStreamVariant.update { selection.stream.identifier }
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
exoPlayer.value?.currentTracks?.let { tracks ->
|
||||||
is StreamSelector.MultiSelection -> {
|
println("gurken trackgroups : ${tracks.groups.size}")
|
||||||
TODO("TRACKSELECTION HAS TO DO THE JOB HERE")
|
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}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +405,8 @@ class NewPlayerImpl(
|
||||||
|
|
||||||
val selection = streamSelector.selectStream(
|
val selection = streamSelector.selectStream(
|
||||||
item,
|
item,
|
||||||
availableStreams = repository.getStreams(item)
|
availableStreams = repository.getStreams(item),
|
||||||
|
demuxedStreamBundeling = StreamSelector.DemuxedStreamBundeling.BUNDLE_STREAMS_WITH_SAME_ID
|
||||||
)
|
)
|
||||||
val mediaSource = builder.buildMediaSource(selection)
|
val mediaSource = builder.buildMediaSource(selection)
|
||||||
uniqueIdToStreamVariantSelection[mediaSource.mediaItem.mediaId.toLong()] = selection
|
uniqueIdToStreamVariantSelection[mediaSource.mediaItem.mediaId.toLong()] = selection
|
||||||
|
|
|
@ -66,7 +66,7 @@ class StreamSelector(
|
||||||
) ?: tryAndGetMedianVideoOnlyStream(availableStreams)?.identifier ?: ""
|
) ?: tryAndGetMedianVideoOnlyStream(availableStreams)?.identifier ?: ""
|
||||||
|
|
||||||
if (demuxedStreamBundeling == DemuxedStreamBundeling.BUNDLE_STREAMS_WITH_SAME_ID) {
|
if (demuxedStreamBundeling == DemuxedStreamBundeling.BUNDLE_STREAMS_WITH_SAME_ID) {
|
||||||
return MultiSelection(item, availableStreams.filter { it.streamType == StreamType.VIDEO || it.streamType == StreamType.AUDIO })
|
return MultiSelection(item, availableStreams.filter { it.streamType != StreamType.DYNAMIC })
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
val videoOnlyStream = getVideoOnlyWithMatchingIdentifier(
|
val videoOnlyStream = getVideoOnlyWithMatchingIdentifier(
|
||||||
|
|
Loading…
Reference in New Issue