-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player] Move Android to per-player-instance Pigeon APIs #9511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
71cad85
e3684d1
bc7452e
18d5e4b
a16cf7e
b8e99a3
ec2ddc7
3406ff6
f41c1b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,9 +21,10 @@ | |||||||||||||||
| * | ||||||||||||||||
| * <p>It provides methods to control playback, adjust volume, and handle seeking. | ||||||||||||||||
| */ | ||||||||||||||||
| public abstract class VideoPlayer { | ||||||||||||||||
| public abstract class VideoPlayer implements Messages.VideoPlayerInstanceApi { | ||||||||||||||||
| @NonNull protected final VideoPlayerCallbacks videoPlayerEvents; | ||||||||||||||||
| @Nullable protected final SurfaceProducer surfaceProducer; | ||||||||||||||||
| @Nullable private DisposeHandler disposeHandler; | ||||||||||||||||
| @NonNull protected ExoPlayer exoPlayer; | ||||||||||||||||
|
|
||||||||||||||||
| /** A closure-compatible signature since {@link java.util.function.Supplier} is API level 24. */ | ||||||||||||||||
|
|
@@ -37,6 +38,11 @@ public interface ExoPlayerProvider { | |||||||||||||||
| ExoPlayer get(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** A handler to run when dispose is called. */ | ||||||||||||||||
| public interface DisposeHandler { | ||||||||||||||||
| void onDispose(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public VideoPlayer( | ||||||||||||||||
| @NonNull VideoPlayerCallbacks events, | ||||||||||||||||
| @NonNull MediaItem mediaItem, | ||||||||||||||||
|
|
@@ -52,6 +58,10 @@ public VideoPlayer( | |||||||||||||||
| setAudioAttributes(exoPlayer, options.mixWithOthers); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public void setDisposeHandler(@Nullable DisposeHandler handler) { | ||||||||||||||||
| disposeHandler = handler; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| @NonNull | ||||||||||||||||
| protected abstract ExoPlayerEventListener createExoPlayerEventListener( | ||||||||||||||||
| @NonNull ExoPlayer exoPlayer, @Nullable SurfaceProducer surfaceProducer); | ||||||||||||||||
|
|
@@ -66,37 +76,48 @@ private static void setAudioAttributes(ExoPlayer exoPlayer, boolean isMixMode) { | |||||||||||||||
| !isMixMode); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| void play() { | ||||||||||||||||
| @Override | ||||||||||||||||
| public void play() { | ||||||||||||||||
| exoPlayer.play(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| void pause() { | ||||||||||||||||
| @Override | ||||||||||||||||
| public void pause() { | ||||||||||||||||
| exoPlayer.pause(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| void setLooping(boolean value) { | ||||||||||||||||
| exoPlayer.setRepeatMode(value ? REPEAT_MODE_ALL : REPEAT_MODE_OFF); | ||||||||||||||||
| @Override | ||||||||||||||||
| public void setLooping(@NonNull Boolean looping) { | ||||||||||||||||
| exoPlayer.setRepeatMode(looping ? REPEAT_MODE_ALL : REPEAT_MODE_OFF); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| void setVolume(double value) { | ||||||||||||||||
| float bracketedValue = (float) Math.max(0.0, Math.min(1.0, value)); | ||||||||||||||||
| @Override | ||||||||||||||||
| public void setVolume(@NonNull Double volume) { | ||||||||||||||||
| float bracketedValue = (float) Math.max(0.0, Math.min(1.0, volume)); | ||||||||||||||||
| exoPlayer.setVolume(bracketedValue); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| void setPlaybackSpeed(double value) { | ||||||||||||||||
| @Override | ||||||||||||||||
| public void setPlaybackSpeed(@NonNull Double speed) { | ||||||||||||||||
| // We do not need to consider pitch and skipSilence for now as we do not handle them and | ||||||||||||||||
| // therefore never diverge from the default values. | ||||||||||||||||
| final PlaybackParameters playbackParameters = new PlaybackParameters(((float) value)); | ||||||||||||||||
| final PlaybackParameters playbackParameters = new PlaybackParameters(speed.floatValue()); | ||||||||||||||||
|
|
||||||||||||||||
| exoPlayer.setPlaybackParameters(playbackParameters); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| void seekTo(int location) { | ||||||||||||||||
| exoPlayer.seekTo(location); | ||||||||||||||||
| @Override | ||||||||||||||||
| public @NonNull Long getPosition() { | ||||||||||||||||
| long position = exoPlayer.getCurrentPosition(); | ||||||||||||||||
| // TODO(stuartmorgan): Move this; this is relying on the fact that getPosition is called | ||||||||||||||||
| // frequently to drive buffering updates, which is a fragile hack. | ||||||||||||||||
| sendBufferingUpdate(); | ||||||||||||||||
| return position; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| long getPosition() { | ||||||||||||||||
| return exoPlayer.getCurrentPosition(); | ||||||||||||||||
| @Override | ||||||||||||||||
| public void seekTo(@NonNull Long position) { | ||||||||||||||||
| exoPlayer.seekTo(position.intValue()); | ||||||||||||||||
| } | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The You should pass the
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| @NonNull | ||||||||||||||||
|
|
@@ -105,6 +126,9 @@ public ExoPlayer getExoPlayer() { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public void dispose() { | ||||||||||||||||
| if (disposeHandler != null) { | ||||||||||||||||
| disposeHandler.onDispose(); | ||||||||||||||||
| } | ||||||||||||||||
| exoPlayer.release(); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hack is pre-existing; it's just being moved from the VideoPlayerPlugin.java version of this method. I added the comment so that future people don't have to go through the same process I did of wondering why getting the position sends a buffer update as a side effect.