Skip to content

Commit

Permalink
fix(player): Save, read and display audio/sub delay correctly (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz authored Oct 29, 2023
1 parent 509eced commit d8327e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
22 changes: 12 additions & 10 deletions app/src/main/java/eu/kanade/tachiyomi/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -540,17 +540,19 @@ class PlayerActivity : BaseActivity() {
}

private fun setupPlayerAudio() {
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
with(playerPreferences) {
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager

val useDeviceVolume = playerPreferences.playerVolumeValue().get() == -1.0F || !playerPreferences.rememberPlayerVolume().get()
fineVolume = if (useDeviceVolume) {
audioManager!!.getStreamVolume(AudioManager.STREAM_MUSIC).toFloat()
} else {
playerPreferences.playerVolumeValue().get()
}
val useDeviceVolume = playerVolumeValue().get() == -1.0F || !rememberPlayerVolume().get()
fineVolume = if (useDeviceVolume) {
audioManager!!.getStreamVolume(AudioManager.STREAM_MUSIC).toFloat()
} else {
playerVolumeValue().get()
}

if (playerPreferences.rememberAudioDelay().get()) {
MPVLib.setPropertyDouble("audio-delay", (playerPreferences.audioDelay().get() / 1000).toDouble())
if (rememberAudioDelay().get()) {
MPVLib.setPropertyDouble("audio-delay", (audioDelay().get() / 1000.0))
}
}

verticalScrollRight(0F)
Expand All @@ -568,7 +570,7 @@ class PlayerActivity : BaseActivity() {
MPVLib.setPropertyString("sub-ass-override", overrideType)

if (rememberSubtitlesDelay().get()) {
MPVLib.setPropertyDouble("sub-delay", subtitlesDelay().get().toDouble())
MPVLib.setPropertyDouble("sub-delay", subtitlesDelay().get() / 1000.0)
}

MPVLib.setPropertyString("sub-bold", if (boldSubtitles().get()) "yes" else "no")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand All @@ -27,7 +29,18 @@ fun SubtitleDelayPage(
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.tiny)) {
val audioDelay by remember { mutableStateOf(screenModel.preferences.rememberAudioDelay()) }
val subDelay by remember { mutableStateOf(screenModel.preferences.rememberSubtitlesDelay()) }

var currentSubDelay by rememberSaveable {
mutableStateOf(
(MPVLib.getPropertyDouble(Tracks.SUBTITLES.mpvProperty) * 1000)
.toInt(),
)
}
var currentAudioDelay by rememberSaveable {
mutableStateOf(
(MPVLib.getPropertyDouble(Tracks.AUDIO.mpvProperty) * 1000)
.toInt(),
)
}
screenModel.ToggleableRow(
textRes = R.string.player_audio_remember_delay,
isChecked = audioDelay.collectAsState().value,
Expand All @@ -43,11 +56,12 @@ fun SubtitleDelayPage(
label = stringResource(id = R.string.player_audio_delay),
placeholder = "0",
suffix = "ms",
value = (MPVLib.getPropertyDouble(Tracks.AUDIO.mpvProperty) * 1000).toInt(),
value = currentAudioDelay,
step = 100,
onValueChanged = {
MPVLib.setPropertyDouble(Tracks.AUDIO.mpvProperty, (it / 1000).toDouble())
MPVLib.setPropertyDouble(Tracks.AUDIO.mpvProperty, it / 1000.0)
screenModel.preferences.audioDelay().set(it)
currentAudioDelay = it
},
)
}
Expand All @@ -69,11 +83,12 @@ fun SubtitleDelayPage(
label = stringResource(id = R.string.player_subtitle_delay),
placeholder = "0",
suffix = "ms",
value = (MPVLib.getPropertyDouble(Tracks.SUBTITLES.mpvProperty) * 1000).toInt(),
value = currentSubDelay,
step = 100,
onValueChanged = {
MPVLib.setPropertyDouble(Tracks.SUBTITLES.mpvProperty, (it / 1000).toDouble())
MPVLib.setPropertyDouble(Tracks.SUBTITLES.mpvProperty, it / 1000.0)
screenModel.preferences.subtitlesDelay().set(it)
currentSubDelay = it
},
)
}
Expand Down

0 comments on commit d8327e8

Please sign in to comment.