Skip to content

Commit

Permalink
Support fast forward and rewind in audio player (#2380)
Browse files Browse the repository at this point in the history
* Support fast forward and rewind in audio player

Signed-off-by: Kevin G <[email protected]>

* Use CDI for UserSettingPreferences

Signed-off-by: Kevin G <[email protected]>

Signed-off-by: Kevin G <[email protected]>
  • Loading branch information
kevgrig authored Jan 4, 2023
1 parent 096a436 commit 4ec0bcb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class MediaManager {
private List<org.jellyfin.sdk.model.api.BaseItemDto> mCurrentVideoQueue;

private Lazy<NavigationRepository> navigationRepository = inject(NavigationRepository.class);
private Lazy<UserSettingPreferences> userPrefs = inject(UserSettingPreferences.class);

public MediaManager(Context context) {
this.context = context;
Expand Down Expand Up @@ -967,7 +969,6 @@ public void playPauseAudio() {
}
}


public void resumeAudio() {
if (mCurrentAudioItem != null && getIsAudioPlayerInitialized()) {
ensureAudioFocus();
Expand All @@ -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;
Expand Down

0 comments on commit 4ec0bcb

Please sign in to comment.