Update playback to match specifications.

This commit is contained in:
Alex Hart
2022-03-30 16:30:06 -03:00
committed by Cody Henthorne
parent 267efb0763
commit 1bb04035ab
10 changed files with 96 additions and 50 deletions

View File

@@ -83,8 +83,8 @@ public class VideoPlayer extends FrameLayout {
this.exoControls = new PlayerControlView(getContext());
this.exoControls.setShowTimeoutMs(-1);
this.exoPlayerListener = new ExoPlayerListener(this, window, playerStateCallback, playerPositionDiscontinuityCallback);
this.playerListener = new Player.Listener() {
this.exoPlayerListener = new ExoPlayerListener();
this.playerListener = new Player.Listener() {
@Override
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
onPlaybackStateChanged(playWhenReady, exoPlayer.getPlaybackState());
@@ -244,9 +244,6 @@ public class VideoPlayer extends FrameLayout {
public void setWindow(@Nullable Window window) {
this.window = window;
if (exoPlayerListener != null) {
exoPlayerListener.setWindow(window);
}
}
public void setPlayerStateCallbacks(@Nullable PlayerStateCallback playerStateCallback) {
@@ -273,35 +270,16 @@ public class VideoPlayer extends FrameLayout {
}
}
private static class ExoPlayerListener implements Player.Listener {
private final VideoPlayer videoPlayer;
private Window window;
private final PlayerStateCallback playerStateCallback;
private final PlayerPositionDiscontinuityCallback playerPositionDiscontinuityCallback;
ExoPlayerListener(@NonNull VideoPlayer videoPlayer,
@Nullable Window window,
@Nullable PlayerStateCallback playerStateCallback,
@Nullable PlayerPositionDiscontinuityCallback playerPositionDiscontinuityCallback)
{
this.videoPlayer = videoPlayer;
this.window = window;
this.playerStateCallback = playerStateCallback;
this.playerPositionDiscontinuityCallback = playerPositionDiscontinuityCallback;
}
private class ExoPlayerListener implements Player.Listener {
@Override
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
onPlaybackStateChanged(playWhenReady, videoPlayer.exoPlayer.getPlaybackState());
onPlaybackStateChanged(playWhenReady, exoPlayer.getPlaybackState());
}
@Override
public void onPlaybackStateChanged(int playbackState) {
onPlaybackStateChanged(videoPlayer.exoPlayer.getPlayWhenReady(), playbackState);
}
public void setWindow(Window window) {
this.window = window;
onPlaybackStateChanged(exoPlayer.getPlayWhenReady(), playbackState);
}
private void onPlaybackStateChanged(boolean playWhenReady, int playbackState) {
@@ -334,7 +312,7 @@ public class VideoPlayer extends FrameLayout {
int reason)
{
if (playerPositionDiscontinuityCallback != null) {
playerPositionDiscontinuityCallback.onPositionDiscontinuity(videoPlayer, reason);
playerPositionDiscontinuityCallback.onPositionDiscontinuity(VideoPlayer.this, reason);
}
}