[Android] ABRepeat: save ab repeat on context change
Duncan McNamara
git at videolan.org
Mon May 15 12:09:54 UTC 2023
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Tue May 9 16:14:04 2023 +0200| [c44187c073fcd98606acc18f7bd0cea8c92fb3f4] | committer: Nicolas Pomepuy
ABRepeat: save ab repeat on context change
Fixes #2840
> https://code.videolan.org/videolan/vlc-android/commit/c44187c073fcd98606acc18f7bd0cea8c92fb3f4
---
.../src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 5 +++--
.../videolan/vlc/gui/video/VideoPlayerActivity.kt | 10 ++++++---
.../src/org/videolan/vlc/media/PlaylistManager.kt | 26 +++++++++++++++++-----
.../interfaces/media/MediaWrapper.java | 2 ++
4 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 65e2994077..e2c6183976 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -209,7 +209,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
}
abRepeatAddMarker.setOnClickListener {
- playlistModel.service?.playlistManager?.setABRepeatValue(binding.timeline.progress.toLong())
+ playlistModel.service?.playlistManager?.setABRepeatValue(playlistModel.service?.playlistManager?.getCurrentMedia(), binding.timeline.progress.toLong())
}
audioPlayProgressMode = Settings.getInstance(requireActivity()).getBoolean(AUDIO_PLAY_PROGRESS_MODE, false)
@@ -665,11 +665,12 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
}
fun onABRepeatStopClick(@Suppress("UNUSED_PARAMETER") v: View) {
+ playlistModel.service?.playlistManager?.resetABRepeatValues(playlistModel.service?.playlistManager?.getCurrentMedia())
playlistModel.service?.playlistManager?.clearABRepeat()
}
fun onABRepeatResetClick(@Suppress("UNUSED_PARAMETER") v: View) {
- playlistModel.service?.playlistManager?.resetABRepeatValues()
+ playlistModel.service?.playlistManager?.resetABRepeatValues(playlistModel.service?.playlistManager?.getCurrentMedia())
}
override fun beforeTextChanged(charSequence: CharSequence, start: Int, before: Int, count: Int) {}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 82510227df..595276c635 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -1756,9 +1756,13 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
R.id.playlist_toggle -> overlayDelegate.togglePlaylist()
R.id.player_overlay_forward -> touchDelegate.seekDelta(Settings.videoJumpDelay * 1000)
R.id.player_overlay_rewind -> touchDelegate.seekDelta(-Settings.videoJumpDelay * 1000)
- R.id.ab_repeat_add_marker -> service?.playlistManager?.setABRepeatValue(overlayDelegate.hudBinding.playerOverlaySeekbar.progress.toLong())
- R.id.ab_repeat_reset -> service?.playlistManager?.resetABRepeatValues()
- R.id.ab_repeat_stop -> service?.playlistManager?.clearABRepeat()
+ R.id.ab_repeat_add_marker -> service?.playlistManager?.setABRepeatValue(
+ service?.playlistManager?.getCurrentMedia(), overlayDelegate.hudBinding.playerOverlaySeekbar.progress.toLong())
+ R.id.ab_repeat_reset -> service?.playlistManager?.resetABRepeatValues(service?.playlistManager?.getCurrentMedia())
+ R.id.ab_repeat_stop -> {
+ service?.playlistManager?.resetABRepeatValues(service?.playlistManager?.getCurrentMedia())
+ service?.playlistManager?.clearABRepeat()
+ }
R.id.player_overlay_navmenu -> showNavMenu()
R.id.player_overlay_length, R.id.player_overlay_time -> toggleTimeDisplay()
R.id.video_renderer -> if (supportFragmentManager.findFragmentByTag("renderers") == null)
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index b77cd1e7be..9fcbc8bd31 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -609,7 +609,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
} else if (settings.getBoolean("save_individual_audio_delay", true)) {
player.setAudioDelay(savedDelay)
}
-
+ val abStart = media.getMetaLong(MediaWrapper.META_AB_REPEAT_START)
+ if (abStart != 0L) {
+ abRepeatOn.value = true
+ abRepeat.value?.start = abStart
+ val abStop = media.getMetaLong(MediaWrapper.META_AB_REPEAT_STOP)
+ abRepeat.value?.stop = if (abStop == 0L) -1L else abStop
+ }
player.setSpuTrack(media.getMetaLong(MediaWrapper.META_SUBTITLE_TRACK).toString())
player.setSpuDelay(media.getMetaLong(MediaWrapper.META_SUBTITLE_DELAY))
val rateString = media.getMetaString(MediaWrapper.META_SPEED)
@@ -922,16 +928,22 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
fun getMediaList(): List<MediaWrapper> = mediaList.copy
- fun setABRepeatValue(time: Long) {
+ fun setABRepeatValue(media: MediaWrapper?, time: Long) {
val value = abRepeat.value ?: ABRepeat()
when {
- value.start == -1L -> value.start = time
- value.start > time -> {
+ value.start == -1L -> {
+ value.start = time
+ }
+ value.start > time && time > -1 -> {
value.stop = value.start
value.start = time
}
- else -> value.stop = time
+ else -> {
+ value.stop = time
+ }
}
+ media?.setLongMeta(MediaWrapper.META_AB_REPEAT_START, value.start)
+ media?.setLongMeta(MediaWrapper.META_AB_REPEAT_STOP, value.stop)
abRepeat.value = value
}
@@ -945,8 +957,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
delayValue.postValue(DelayValues())
}
- fun resetABRepeatValues() {
+ fun resetABRepeatValues(media: MediaWrapper?) {
abRepeat.value = ABRepeat()
+ media?.setLongMeta(MediaWrapper.META_AB_REPEAT_START, 0L)
+ media?.setLongMeta(MediaWrapper.META_AB_REPEAT_STOP, 0L)
}
fun toggleABRepeat() {
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
index 25154c09c4..a052f77709 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MediaWrapper.java
@@ -73,6 +73,8 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
public final static int META_CROP = 103;
public final static int META_DEINTERLACE = 104;
public final static int META_VIDEOFILTER = 105;
+ public final static int META_AB_REPEAT_START = 106;
+ public final static int META_AB_REPEAT_STOP = 107;
//Audio
public final static int META_AUDIOTRACK = 150;
public final static int META_GAIN = 151;
More information about the Android
mailing list