From c730306e3a408be753febf6e5a6e9c2984a3bbb5 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Mon, 22 Apr 2024 10:35:51 +0200 Subject: [PATCH] fix(android): seek callback with controls (#3694) * fix(ts): onPlaybackRateChangeData was not correctly typed * fix: ensure tracks are well displayed in the sample * fix(android): add onSeek callback when controls are enable * chore: remove seekTime which is useless now --- .../exoplayer/ReactExoplayerView.java | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 37770b34..d119e3c1 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -185,7 +185,6 @@ public class ReactExoplayerView extends FrameLayout implements private float audioVolume = 1f; private int minLoadRetryCount = 3; private int maxBitRate = 0; - private long seekTime = C.TIME_UNSET; private boolean hasDrmFailed = false; private boolean isUsingContentResolution = false; private boolean selectTrackWhenReady = false; @@ -1380,7 +1379,15 @@ public class ReactExoplayerView extends FrameLayout implements } @Override - public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @NonNull Player.PositionInfo newPosition, int reason) { + public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @NonNull Player.PositionInfo newPosition, @Player.DiscontinuityReason int reason) { + if (reason == Player.DISCONTINUITY_REASON_SEEK) { + eventEmitter.seek(player.getCurrentPosition(), newPosition.positionMs % 1000); // time are in seconds /°\ + if (isUsingContentResolution) { + // We need to update the selected track to make sure that it still matches user selection if track list has changed in this period + setSelectedTrack(C.TRACK_TYPE_VIDEO, videoTrackType, videoTrackValue); + } + } + if (playerNeedsSource) { // This will only occur if the user has performed a seek whilst in the error state. Update the // resume position so that if the user then retries, playback will resume from the position to @@ -1405,28 +1412,6 @@ public class ReactExoplayerView extends FrameLayout implements // Do nothing. } - @Override - public void onPlaybackStateChanged(int playbackState) { - if (playbackState == Player.STATE_READY && seekTime != C.TIME_UNSET) { - eventEmitter.seek(player.getCurrentPosition(), seekTime); - seekTime = C.TIME_UNSET; - if (isUsingContentResolution) { - // We need to update the selected track to make sure that it still matches user selection if track list has changed in this period - setSelectedTrack(C.TRACK_TYPE_VIDEO, videoTrackType, videoTrackValue); - } - } - } - - @Override - public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) { - // Do nothing. - } - - @Override - public void onRepeatModeChanged(int repeatMode) { - // Do nothing. - } - @Override public void onTracksChanged(@NonNull Tracks tracks) { eventEmitter.textTracks(getTextTrackInfo()); @@ -1900,7 +1885,6 @@ public class ReactExoplayerView extends FrameLayout implements public void seekTo(long positionMs) { if (player != null) { - seekTime = positionMs; player.seekTo(positionMs); } }