Skip to content

Commit

Permalink
feat(player): save position setting
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Jun 20, 2024
1 parent f430cce commit 7aaf01e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ class PlayerPreferences(
val showChaptersButton = preferenceStore.getBoolean("show_video_chapters_button", false)

val defaultSpeed = preferenceStore.getFloat("default_speed", 1f)
val savePositionOnQuit = preferenceStore.getBoolean("save_position", true)
}
14 changes: 9 additions & 5 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class PlayerActivity : AppCompatActivity() {
}
player.playbackSpeed = playerPreferences.defaultSpeed.get().toDouble()
MPVLib.setPropertyString("keep-open", "yes")
if (playerPreferences.savePositionOnQuit.get()) {
MPVLib.setPropertyString("save-position-on-quit", "yes")
}

player.addObserver(PlayerObserver(this))
}
Expand Down Expand Up @@ -221,6 +224,7 @@ class PlayerActivity : AppCompatActivity() {
"paused-for-cache" -> {
viewModel.isLoading.update { value }
}

"seeking" -> {
viewModel.isLoading.update { value }
}
Expand All @@ -234,12 +238,12 @@ class PlayerActivity : AppCompatActivity() {
internal fun event(eventId: Int) {
when (eventId) {
MPVLib.mpvEventId.MPV_EVENT_FILE_LOADED -> {
setOrientation()
viewModel.changeVideoAspect(playerPreferences.videoAspect.get())
CoroutineScope(Dispatchers.IO).launch {
reuseVideoPlaybackState(MPVLib.getPropertyString("media-title"))
if (intent.hasExtra("position")) setupIntents(intent)
}
setOrientation()
viewModel.changeVideoAspect(playerPreferences.videoAspect.get())
viewModel.duration.value = player.duration!!.toFloat()
viewModel.loadChapters()
viewModel.loadTracks()
Expand All @@ -260,11 +264,11 @@ class PlayerActivity : AppCompatActivity() {
mpvKtDatabase.videoDataDao().upsert(
PlaybackStateEntity(
MPVLib.getPropertyString("media-title"),
player.timePos?: 0,
if (playerPreferences.savePositionOnQuit.get()) player.timePos ?: 0 else 0,
player.sid,
player.secondarySid,
player.aid
)
player.aid,
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ object PlayerPreferencesScreen : Screen {
defaultValue = preferences.drawOverDisplayCutout.defaultValue(),
title = { Text(stringResource(R.string.pref_player_draw_over_cutout)) },
)
switchPreference(
key = preferences.savePositionOnQuit.key(),
defaultValue = preferences.savePositionOnQuit.defaultValue(),
title = { Text(stringResource(R.string.pref_player_save_position_on_quit)) },
)
switchPreference(
key = preferences.doubleTapToPause.key(),
defaultValue = preferences.doubleTapToPause.defaultValue(),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="pref_player_orientation_reverse_landscape">Reverse landscape</string>
<string name="pref_player_orientation_sensor_landscape">Sensor landscape</string>
<string name="pref_player_draw_over_cutout">Draw over display cutout</string>
<string name="pref_player_save_position_on_quit">Save position on quit</string>
<string name="pref_player_double_tap_to_pause">Double tap to pause</string>
<string name="pref_player_double_tap_to_seek">Double tap to seek</string>
<string name="pref_player_double_tap_seek_duration">Double tap seek duration</string>
Expand Down

0 comments on commit 7aaf01e

Please sign in to comment.