Migrate GL demo from deprecated ExoPlayer.VideoComponent to ExoPlayer

#minor-release

PiperOrigin-RevId: 408304187
This commit is contained in:
ibaker 2021-11-08 12:08:04 +00:00 committed by Ian Baker
parent 54af82a23f
commit fc7b66706f
2 changed files with 18 additions and 20 deletions

View File

@ -179,8 +179,7 @@ public final class MainActivity extends Activity {
player.play(); player.play();
VideoProcessingGLSurfaceView videoProcessingGLSurfaceView = VideoProcessingGLSurfaceView videoProcessingGLSurfaceView =
Assertions.checkNotNull(this.videoProcessingGLSurfaceView); Assertions.checkNotNull(this.videoProcessingGLSurfaceView);
videoProcessingGLSurfaceView.setVideoComponent( videoProcessingGLSurfaceView.setPlayer(player);
Assertions.checkNotNull(player.getVideoComponent()));
Assertions.checkNotNull(playerView).setPlayer(player); Assertions.checkNotNull(playerView).setPlayer(player);
player.addAnalyticsListener(new EventLogger(/* trackSelector= */ null)); player.addAnalyticsListener(new EventLogger(/* trackSelector= */ null));
this.player = player; this.player = player;
@ -188,9 +187,9 @@ public final class MainActivity extends Activity {
private void releasePlayer() { private void releasePlayer() {
Assertions.checkNotNull(playerView).setPlayer(null); Assertions.checkNotNull(playerView).setPlayer(null);
Assertions.checkNotNull(videoProcessingGLSurfaceView).setPlayer(null);
if (player != null) { if (player != null) {
player.release(); player.release();
Assertions.checkNotNull(videoProcessingGLSurfaceView).setVideoComponent(null);
player = null; player = null;
} }
} }

View File

@ -73,7 +73,7 @@ public final class VideoProcessingGLSurfaceView extends GLSurfaceView {
@Nullable private SurfaceTexture surfaceTexture; @Nullable private SurfaceTexture surfaceTexture;
@Nullable private Surface surface; @Nullable private Surface surface;
@Nullable private ExoPlayer.VideoComponent videoComponent; @Nullable private ExoPlayer player;
/** /**
* Creates a new instance. Pass {@code true} for {@code requireSecureContext} if the {@link * Creates a new instance. Pass {@code true} for {@code requireSecureContext} if the {@link
@ -147,25 +147,24 @@ public final class VideoProcessingGLSurfaceView extends GLSurfaceView {
} }
/** /**
* Attaches or detaches (if {@code newVideoComponent} is {@code null}) this view from the video * Attaches or detaches (if {@code player} is {@code null}) this view from the player.
* component of the player.
* *
* @param newVideoComponent The new video component, or {@code null} to detach this view. * @param player The new player, or {@code null} to detach this view.
*/ */
public void setVideoComponent(@Nullable ExoPlayer.VideoComponent newVideoComponent) { public void setPlayer(@Nullable ExoPlayer player) {
if (newVideoComponent == videoComponent) { if (player == this.player) {
return; return;
} }
if (videoComponent != null) { if (this.player != null) {
if (surface != null) { if (surface != null) {
videoComponent.clearVideoSurface(surface); this.player.clearVideoSurface(surface);
} }
videoComponent.clearVideoFrameMetadataListener(renderer); this.player.clearVideoFrameMetadataListener(renderer);
} }
videoComponent = newVideoComponent; this.player = player;
if (videoComponent != null) { if (this.player != null) {
videoComponent.setVideoFrameMetadataListener(renderer); this.player.setVideoFrameMetadataListener(renderer);
videoComponent.setVideoSurface(surface); this.player.setVideoSurface(surface);
} }
} }
@ -176,8 +175,8 @@ public final class VideoProcessingGLSurfaceView extends GLSurfaceView {
mainHandler.post( mainHandler.post(
() -> { () -> {
if (surface != null) { if (surface != null) {
if (videoComponent != null) { if (player != null) {
videoComponent.setVideoSurface(null); player.setVideoSurface(null);
} }
releaseSurface(surfaceTexture, surface); releaseSurface(surfaceTexture, surface);
surfaceTexture = null; surfaceTexture = null;
@ -194,8 +193,8 @@ public final class VideoProcessingGLSurfaceView extends GLSurfaceView {
this.surfaceTexture = surfaceTexture; this.surfaceTexture = surfaceTexture;
this.surface = new Surface(surfaceTexture); this.surface = new Surface(surfaceTexture);
releaseSurface(oldSurfaceTexture, oldSurface); releaseSurface(oldSurfaceTexture, oldSurface);
if (videoComponent != null) { if (player != null) {
videoComponent.setVideoSurface(surface); player.setVideoSurface(surface);
} }
}); });
} }