Skip to content

Commit

Permalink
feat(subtitles): add setting to skip applying subtitle styles
Browse files Browse the repository at this point in the history
useful if you want to use mpv.conf for that (to share them around)
* fix: seekbar causing crashes when opening subsequent videos
  • Loading branch information
abdallahmehiz committed Sep 4, 2024
1 parent 6baa029 commit fa93eeb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SubtitlesPreferences(preferenceStore: PreferenceStore) {
val defaultSubDelay = preferenceStore.getInt("sub_default_delay")
val defaultSubSpeed = preferenceStore.getFloat("sub_default_speed", 1f)
val defaultSecondarySubDelay = preferenceStore.getInt("sub_default_secondary_delay")

val skipSubtitlesStyling = preferenceStore.getBoolean("skip_sub_styling")
}

enum class SubtitleJustification(
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,18 @@ class PlayerActivity : AppCompatActivity() {
lifecycleScope.launch(Dispatchers.IO) { copyMPVFonts() }

MPVLib.setPropertyString("slang", subtitlesPreferences.preferredLanguages.get())

MPVLib.setPropertyString("sub-fonts-dir", cacheDir.path + "/fonts/")
MPVLib.setPropertyDouble("sub-delay", subtitlesPreferences.defaultSubDelay.get() / 1000.0)
MPVLib.setPropertyDouble("sub-speed", subtitlesPreferences.defaultSubSpeed.get().toDouble())
MPVLib.setPropertyDouble("secondary-sub-delay", subtitlesPreferences.defaultSecondarySubDelay.get() / 1000.0)

if (subtitlesPreferences.skipSubtitlesStyling.get()) return
MPVLib.setPropertyString("sub-font", subtitlesPreferences.font.get())
subtitlesPreferences.overrideAssSubs.get().let {
MPVLib.setPropertyString("sub-ass-override", if (it) "force" else "no")
MPVLib.setPropertyBoolean("sub-ass-justify", it)
}

MPVLib.setPropertyString("sub-fonts-dir", cacheDir.path + "/fonts/")
MPVLib.setPropertyString("sub-font", subtitlesPreferences.font.get())

MPVLib.setPropertyInt("sub-font-size", subtitlesPreferences.fontSize.get())
MPVLib.setPropertyBoolean("sub-bold", subtitlesPreferences.bold.get())
MPVLib.setPropertyBoolean("sub-italic", subtitlesPreferences.italic.get())
Expand All @@ -247,10 +251,6 @@ class PlayerActivity : AppCompatActivity() {
MPVLib.setPropertyInt("sub-border-size", subtitlesPreferences.borderSize.get())
MPVLib.setPropertyString("sub-border-color", subtitlesPreferences.borderColor.get().toColorHexString())
MPVLib.setPropertyString("sub-back-color", subtitlesPreferences.backgroundColor.get().toColorHexString())

MPVLib.setPropertyDouble("sub-delay", subtitlesPreferences.defaultSubDelay.get() / 1000.0)
MPVLib.setPropertyDouble("sub-speed", subtitlesPreferences.defaultSubSpeed.get().toDouble())
MPVLib.setPropertyDouble("secondary-sub-delay", subtitlesPreferences.defaultSecondarySubDelay.get() / 1000.0)
}

private fun copyMPVConfigFiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun SeekbarWithTimers(
modifier = Modifier.width(92.dp),
)
Seeker(
value = position,
value = position.coerceIn(0f, duration),
range = 0f..duration,
onValueChange = onValueChange,
onValueChangeFinished = onValueChangeFinished,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow
import live.mehiz.mpvkt.R
import live.mehiz.mpvkt.preferences.AudioChannels
import live.mehiz.mpvkt.preferences.AudioPreferences
import live.mehiz.mpvkt.preferences.preference.collectAsState
import live.mehiz.mpvkt.presentation.Screen
import me.zhanghai.compose.preference.ProvidePreferenceLocals
import me.zhanghai.compose.preference.listPreference
Expand All @@ -40,7 +39,6 @@ object AudioPreferencesScreen : Screen() {
val context = LocalContext.current
val navigator = LocalNavigator.currentOrThrow
val preferences = koinInject<AudioPreferences>()
val audioChannels by preferences.audioChannels.collectAsState()

Scaffold(
topBar = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import live.mehiz.mpvkt.preferences.SubtitlesPreferences
import live.mehiz.mpvkt.preferences.preference.collectAsState
import live.mehiz.mpvkt.presentation.Screen
import me.zhanghai.compose.preference.ProvidePreferenceLocals
import me.zhanghai.compose.preference.switchPreference
import me.zhanghai.compose.preference.textFieldPreference
import me.zhanghai.compose.preference.twoTargetIconButtonPreference
import org.koin.compose.koinInject
Expand Down Expand Up @@ -101,6 +102,12 @@ object SubtitlesPreferencesScreen : Screen() {
onIconButtonClick = { preferences.fontsFolder.delete() },
iconButtonEnabled = fontsFolder.isNotBlank()
)
switchPreference(
preferences.skipSubtitlesStyling.key(),
defaultValue = preferences.skipSubtitlesStyling.defaultValue(),
title = { Text(stringResource(R.string.pref_subtitles_skip_applying_subtitles_styling)) },
summary = { Text(stringResource(R.string.pref_subtitles_skip_applying_subtitles_styling_summary)) }
)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<string name="pref_preferred_languages">Preferred languages</string>
<string name="pref_subtitles_fonts_dir">Fonts directory</string>
<string name="pref_subtitles_preferred_language">Subtitle language(s) to be selected by default on a video with multiple subtitles, Two- or three-letter languages codes work. Multiple values can be delimited by comma.</string>
<string name="pref_subtitles_skip_applying_subtitles_styling">Skip applying subtitles styling</string>
<string name="pref_subtitles_skip_applying_subtitles_styling_summary">Enable if you wish to style the subtitles through mpv.conf</string>

<string name="pref_audio">Audio</string>
<string name="pref_audio_summary">Preferred languages, audio channels, pitch correction</string>
Expand Down

0 comments on commit fa93eeb

Please sign in to comment.