mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-03 16:59:08 +00:00
adjust audio track info logic
This commit is contained in:
parent
5668f4ef3c
commit
fc16bf9e8b
1 changed files with 31 additions and 2 deletions
|
|
@ -41,6 +41,7 @@ import androidx.media3.ui.AspectRatioFrameLayout
|
|||
import androidx.media3.ui.PlayerView
|
||||
import androidx.media3.ui.SubtitleView
|
||||
import androidx.media3.ui.CaptionStyleCompat
|
||||
import com.nuvio.app.features.trailer.YoutubeChunkedDataSourceFactory
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
|
@ -49,6 +50,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.util.Locale
|
||||
|
||||
private const val TAG = "NuvioPlayer"
|
||||
|
||||
|
|
@ -111,7 +113,7 @@ actual fun PlatformPlayerSurface(
|
|||
.setTsExtractorTimestampSearchBytes(1500 * TsExtractor.TS_PACKET_SIZE)
|
||||
|
||||
val mediaSourceFactory = DefaultMediaSourceFactory(
|
||||
PlatformPlaybackDataSourceFactory.create(defaultRequestHeaders = sanitizedSourceHeaders),
|
||||
YoutubeChunkedDataSourceFactory(defaultRequestHeaders = sanitizedSourceHeaders),
|
||||
extractorsFactory,
|
||||
)
|
||||
|
||||
|
|
@ -434,11 +436,38 @@ private fun ExoPlayer.extractAudioTracks(): List<AudioTrack> {
|
|||
for (group in currentTracks.groups) {
|
||||
if (group.type != C.TRACK_TYPE_AUDIO) continue
|
||||
val format = group.mediaTrackGroup.getFormat(0)
|
||||
val channelLabel = when {
|
||||
format.channelCount == 1 -> "Mono"
|
||||
format.channelCount == 2 -> "Stereo"
|
||||
format.channelCount == 6 -> "5.1"
|
||||
format.channelCount == 8 -> "7.1"
|
||||
format.channelCount > 0 -> "${format.channelCount}ch"
|
||||
else -> null
|
||||
}
|
||||
val mime = format.sampleMimeType?.lowercase()
|
||||
val codecLabel = when {
|
||||
mime == null -> null
|
||||
mime.contains("eac3-joc") -> "Dolby Atmos"
|
||||
mime.contains("truehd") && format.channelCount >= 8 -> "Dolby Atmos"
|
||||
mime.contains("truehd") -> "Dolby TrueHD"
|
||||
mime.contains("eac3") -> "Dolby Digital Plus"
|
||||
mime.contains("ac3") -> "Dolby Digital"
|
||||
mime.contains("opus") -> "Opus"
|
||||
mime.contains("aac") -> "AAC"
|
||||
mime.contains("dts-hd") -> "DTS-HD"
|
||||
mime.contains("dts") -> "DTS"
|
||||
else -> null
|
||||
}
|
||||
val resolvedLanguage = format.language?.let { lang -> Locale(lang).displayLanguage.takeIf { name -> name.isNotBlank() && name != lang } }
|
||||
val baseName = format.label?.takeIf { it.isNotBlank() } ?: resolvedLanguage ?: format.language ?: "Track ${idx + 1}"
|
||||
val suffix = listOfNotNull(channelLabel, codecLabel)
|
||||
.joinToString(" ")
|
||||
.let { if (it.isNotBlank()) " ($it)" else "" }
|
||||
tracks.add(
|
||||
AudioTrack(
|
||||
index = idx,
|
||||
id = format.id ?: idx.toString(),
|
||||
label = format.label ?: "",
|
||||
label = "$baseName$suffix",
|
||||
language = format.language,
|
||||
isSelected = group.isSelected,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue