Workaround for switching direct play audio tracks

This commit is contained in:
Damontecres 2026-03-17 13:36:26 -04:00
parent a674867656
commit 5d6b8ff1fe
No known key found for this signature in database

View file

@ -50,6 +50,7 @@ import com.github.damontecres.wholphin.services.RefreshRateService
import com.github.damontecres.wholphin.services.ScreensaverService import com.github.damontecres.wholphin.services.ScreensaverService
import com.github.damontecres.wholphin.services.StreamChoiceService import com.github.damontecres.wholphin.services.StreamChoiceService
import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.services.UserPreferencesService
import com.github.damontecres.wholphin.ui.gt
import com.github.damontecres.wholphin.ui.isNotNullOrBlank import com.github.damontecres.wholphin.ui.isNotNullOrBlank
import com.github.damontecres.wholphin.ui.launchDefault import com.github.damontecres.wholphin.ui.launchDefault
import com.github.damontecres.wholphin.ui.launchIO import com.github.damontecres.wholphin.ui.launchIO
@ -794,12 +795,26 @@ class PlaybackViewModel
userInitiated: Boolean, userInitiated: Boolean,
): Boolean = ): Boolean =
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
// TODO there's probably no reason why we can't add external subtitles?
Timber.v("changeStreams direct play") Timber.v("changeStreams direct play")
// TODO Better way to handle unsupported types in general is needed
// This is a workaround for switching to a non AC3 track when the user wants audio transcoded to AC3
if (preferences.appPreferences.playbackPreferences.overrides.preferAc3Surround && audioIndex != null) {
currentPlayback.mediaSourceInfo.mediaStreams
.orEmpty()
.firstOrNull { it.index == audioIndex }
?.let {
if (it.channels.gt(2) && it.codec != Codec.Audio.AC3) {
// User wants to transcode audio into AC3
return@withContext false
}
}
}
val source = currentPlayback.mediaSourceInfo val source = currentPlayback.mediaSourceInfo
val externalSubtitle = source.findExternalSubtitle(subtitleIndex) val externalSubtitle = source.findExternalSubtitle(subtitleIndex)
// TODO there's probably no reason why we can't add external subtitles?
if (externalSubtitle == null) { if (externalSubtitle == null) {
val result = val result =
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {