From 4ec0bcba724c77de2745c459a201032f845a2a32 Mon Sep 17 00:00:00 2001 From: kevgrig Date: Wed, 4 Jan 2023 01:55:00 -0600 Subject: [PATCH] Support fast forward and rewind in audio player (#2380) * Support fast forward and rewind in audio player Signed-off-by: Kevin G * Use CDI for UserSettingPreferences Signed-off-by: Kevin G Signed-off-by: Kevin G --- .../ui/playback/AudioNowPlayingFragment.java | 8 +++-- .../androidtv/ui/playback/MediaManager.java | 29 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/AudioNowPlayingFragment.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/AudioNowPlayingFragment.java index 9fc2f8d139..b8c8662605 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/AudioNowPlayingFragment.java +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/AudioNowPlayingFragment.java @@ -323,13 +323,17 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { } return true; case KeyEvent.KEYCODE_MEDIA_NEXT: - case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: mediaManager.getValue().nextAudioItem(); return true; + case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: + mediaManager.getValue().fastForward(); + return true; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: - case KeyEvent.KEYCODE_MEDIA_REWIND: mediaManager.getValue().prevAudioItem(); return true; + case KeyEvent.KEYCODE_MEDIA_REWIND: + mediaManager.getValue().rewind(); + return true; case KeyEvent.KEYCODE_DPAD_RIGHT: if (ssActive) { mediaManager.getValue().nextAudioItem(); diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/MediaManager.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/MediaManager.java index b00fb2bdcd..a9f15b075b 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/MediaManager.java +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/MediaManager.java @@ -27,6 +27,7 @@ import org.jellyfin.androidtv.data.compat.AudioOptions; import org.jellyfin.androidtv.data.compat.StreamInfo; import org.jellyfin.androidtv.data.model.DataRefreshService; +import org.jellyfin.androidtv.preference.UserSettingPreferences; import org.jellyfin.androidtv.ui.itemhandling.AudioQueueItem; import org.jellyfin.androidtv.ui.itemhandling.BaseRowItem; import org.jellyfin.androidtv.ui.itemhandling.ItemRowAdapter; @@ -98,6 +99,7 @@ public class MediaManager { private List mCurrentVideoQueue; private Lazy navigationRepository = inject(NavigationRepository.class); + private Lazy userPrefs = inject(UserSettingPreferences.class); public MediaManager(Context context) { this.context = context; @@ -967,7 +969,6 @@ public void playPauseAudio() { } } - public void resumeAudio() { if (mCurrentAudioItem != null && getIsAudioPlayerInitialized()) { ensureAudioFocus(); @@ -985,6 +986,32 @@ public void resumeAudio() { } } + public void fastForward() { + seek(userPrefs.getValue().get(UserSettingPreferences.Companion.getSkipForwardLength())); + } + + public void rewind() { + seek(-userPrefs.getValue().get(UserSettingPreferences.Companion.getSkipBackLength())); + } + + public void seek(int offset) { + if (mCurrentAudioItem != null && isPlayingAudio()) { + if (nativeMode) { + Timber.d("Fast forward %d with ExoPlayer", offset); + if (mExoPlayer.isCurrentMediaItemSeekable()) { + mCurrentAudioPosition = Utils.getSafeSeekPosition(mExoPlayer.getCurrentPosition() + offset, mExoPlayer.getDuration()); + mExoPlayer.seekTo(mCurrentAudioPosition); + } + } else { + Timber.d("Fast forward %d with VLC Player", offset); + if (mVlcPlayer.isSeekable()) { + mCurrentAudioPosition = Utils.getSafeSeekPosition(mVlcPlayer.getTime() + offset, mVlcPlayer.getLength()); + mVlcPlayer.setTime(mCurrentAudioPosition); + } + } + } + } + public void setCurrentMediaPosition(int currentMediaPosition) { if (currentMediaPosition < 0) return; if (mCurrentMediaAdapter == null && mCurrentVideoQueue == null) return;