mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-21 20:27:06 +03:00
fix(player): Save, read and display audio/sub delay correctly (#1183)
This commit is contained in:
parent
509ecedb3a
commit
d8327e872d
2 changed files with 32 additions and 15 deletions
|
@ -540,17 +540,19 @@ class PlayerActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupPlayerAudio() {
|
private fun setupPlayerAudio() {
|
||||||
|
with(playerPreferences) {
|
||||||
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
|
|
||||||
val useDeviceVolume = playerPreferences.playerVolumeValue().get() == -1.0F || !playerPreferences.rememberPlayerVolume().get()
|
val useDeviceVolume = playerVolumeValue().get() == -1.0F || !rememberPlayerVolume().get()
|
||||||
fineVolume = if (useDeviceVolume) {
|
fineVolume = if (useDeviceVolume) {
|
||||||
audioManager!!.getStreamVolume(AudioManager.STREAM_MUSIC).toFloat()
|
audioManager!!.getStreamVolume(AudioManager.STREAM_MUSIC).toFloat()
|
||||||
} else {
|
} else {
|
||||||
playerPreferences.playerVolumeValue().get()
|
playerVolumeValue().get()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerPreferences.rememberAudioDelay().get()) {
|
if (rememberAudioDelay().get()) {
|
||||||
MPVLib.setPropertyDouble("audio-delay", (playerPreferences.audioDelay().get() / 1000).toDouble())
|
MPVLib.setPropertyDouble("audio-delay", (audioDelay().get() / 1000.0))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
verticalScrollRight(0F)
|
verticalScrollRight(0F)
|
||||||
|
@ -568,7 +570,7 @@ class PlayerActivity : BaseActivity() {
|
||||||
MPVLib.setPropertyString("sub-ass-override", overrideType)
|
MPVLib.setPropertyString("sub-ass-override", overrideType)
|
||||||
|
|
||||||
if (rememberSubtitlesDelay().get()) {
|
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")
|
MPVLib.setPropertyString("sub-bold", if (boldSubtitles().get()) "yes" else "no")
|
||||||
|
|
|
@ -10,6 +10,8 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
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.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
@ -27,7 +29,18 @@ fun SubtitleDelayPage(
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.tiny)) {
|
Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.tiny)) {
|
||||||
val audioDelay by remember { mutableStateOf(screenModel.preferences.rememberAudioDelay()) }
|
val audioDelay by remember { mutableStateOf(screenModel.preferences.rememberAudioDelay()) }
|
||||||
val subDelay by remember { mutableStateOf(screenModel.preferences.rememberSubtitlesDelay()) }
|
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(
|
screenModel.ToggleableRow(
|
||||||
textRes = R.string.player_audio_remember_delay,
|
textRes = R.string.player_audio_remember_delay,
|
||||||
isChecked = audioDelay.collectAsState().value,
|
isChecked = audioDelay.collectAsState().value,
|
||||||
|
@ -43,11 +56,12 @@ fun SubtitleDelayPage(
|
||||||
label = stringResource(id = R.string.player_audio_delay),
|
label = stringResource(id = R.string.player_audio_delay),
|
||||||
placeholder = "0",
|
placeholder = "0",
|
||||||
suffix = "ms",
|
suffix = "ms",
|
||||||
value = (MPVLib.getPropertyDouble(Tracks.AUDIO.mpvProperty) * 1000).toInt(),
|
value = currentAudioDelay,
|
||||||
step = 100,
|
step = 100,
|
||||||
onValueChanged = {
|
onValueChanged = {
|
||||||
MPVLib.setPropertyDouble(Tracks.AUDIO.mpvProperty, (it / 1000).toDouble())
|
MPVLib.setPropertyDouble(Tracks.AUDIO.mpvProperty, it / 1000.0)
|
||||||
screenModel.preferences.audioDelay().set(it)
|
screenModel.preferences.audioDelay().set(it)
|
||||||
|
currentAudioDelay = it
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -69,11 +83,12 @@ fun SubtitleDelayPage(
|
||||||
label = stringResource(id = R.string.player_subtitle_delay),
|
label = stringResource(id = R.string.player_subtitle_delay),
|
||||||
placeholder = "0",
|
placeholder = "0",
|
||||||
suffix = "ms",
|
suffix = "ms",
|
||||||
value = (MPVLib.getPropertyDouble(Tracks.SUBTITLES.mpvProperty) * 1000).toInt(),
|
value = currentSubDelay,
|
||||||
step = 100,
|
step = 100,
|
||||||
onValueChanged = {
|
onValueChanged = {
|
||||||
MPVLib.setPropertyDouble(Tracks.SUBTITLES.mpvProperty, (it / 1000).toDouble())
|
MPVLib.setPropertyDouble(Tracks.SUBTITLES.mpvProperty, it / 1000.0)
|
||||||
screenModel.preferences.subtitlesDelay().set(it)
|
screenModel.preferences.subtitlesDelay().set(it)
|
||||||
|
currentSubDelay = it
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue