Move TextComponent to ExoPlayer

PiperOrigin-RevId: 368428647
This commit is contained in:
krocard 2021-04-14 15:49:04 +01:00 committed by Andrew Lewis
parent bd654279d7
commit 5ae84ab5f4
8 changed files with 62 additions and 60 deletions

View File

@ -34,6 +34,7 @@ import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
@ -55,7 +56,7 @@ import com.google.android.gms.cast.framework.media.RemoteMediaClient;
import com.google.android.gms.cast.framework.media.RemoteMediaClient.MediaChannelResult; import com.google.android.gms.cast.framework.media.RemoteMediaClient.MediaChannelResult;
import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.api.ResultCallback;
import java.util.Collections; import com.google.common.collect.ImmutableList;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.RequiresNonNull; import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@ -280,12 +281,6 @@ public final class CastPlayer extends BasePlayer {
return null; return null;
} }
@Override
@Nullable
public TextComponent getTextComponent() {
return null;
}
@Override @Override
@Nullable @Nullable
public DeviceComponent getDeviceComponent() { public DeviceComponent getDeviceComponent() {
@ -562,9 +557,9 @@ public final class CastPlayer extends BasePlayer {
} }
@Override @Override
public List<Metadata> getCurrentStaticMetadata() { public ImmutableList<Metadata> getCurrentStaticMetadata() {
// CastPlayer does not currently support metadata. // CastPlayer does not currently support metadata.
return Collections.emptyList(); return ImmutableList.of();
} }
@Override @Override
@ -664,6 +659,12 @@ public final class CastPlayer extends BasePlayer {
return 1; return 1;
} }
/** This method is not supported and returns an empty list. */
@Override
public ImmutableList<Cue> getCurrentCues() {
return ImmutableList.of();
}
// Internal methods. // Internal methods.
// Call deprecated callbacks. // Call deprecated callbacks.

View File

@ -206,27 +206,6 @@ public interface Player {
void clearVideoTextureView(@Nullable TextureView textureView); void clearVideoTextureView(@Nullable TextureView textureView);
} }
/** The text component of a {@link Player}. */
interface TextComponent {
/**
* Registers an output to receive text events.
*
* @param listener The output to register.
*/
void addTextOutput(TextOutput listener);
/**
* Removes a text output.
*
* @param listener The output to remove.
*/
void removeTextOutput(TextOutput listener);
/** Returns the current {@link Cue Cues}. This list may be empty. */
List<Cue> getCurrentCues();
}
/** The device component of a {@link Player}. */ /** The device component of a {@link Player}. */
interface DeviceComponent { interface DeviceComponent {
@ -1151,10 +1130,6 @@ public interface Player {
@Nullable @Nullable
VideoComponent getVideoComponent(); VideoComponent getVideoComponent();
/** Returns the component of this player for text output, or null if text is not supported. */
@Nullable
TextComponent getTextComponent();
/** Returns the component of this player for playback device, or null if it's not supported. */ /** Returns the component of this player for playback device, or null if it's not supported. */
@Nullable @Nullable
DeviceComponent getDeviceComponent(); DeviceComponent getDeviceComponent();
@ -1832,4 +1807,7 @@ public interface Player {
* @return The linear gain applied to all audio channels. * @return The linear gain applied to all audio channels.
*/ */
float getVolume(); float getVolume();
/** Returns the current {@link Cue Cues}. This list may be empty. */
List<Cue> getCurrentCues();
} }

View File

@ -34,6 +34,8 @@ import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory; import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.text.TextRenderer; import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
@ -219,6 +221,27 @@ public interface ExoPlayer extends Player {
boolean getSkipSilenceEnabled(); boolean getSkipSilenceEnabled();
} }
/** The text component of an {@link ExoPlayer}. */
interface TextComponent {
/**
* Registers an output to receive text events.
*
* @param listener The output to register.
*/
void addTextOutput(TextOutput listener);
/**
* Removes a text output.
*
* @param listener The output to remove.
*/
void removeTextOutput(TextOutput listener);
/** Returns the current {@link Cue Cues}. This list may be empty. */
List<Cue> getCurrentCues();
}
/** The metadata component of an {@link ExoPlayer}. */ /** The metadata component of an {@link ExoPlayer}. */
interface MetadataComponent { interface MetadataComponent {
@ -580,6 +603,10 @@ public interface ExoPlayer extends Player {
@Nullable @Nullable
AudioComponent getAudioComponent(); AudioComponent getAudioComponent();
/** Returns the component of this player for text output, or null if text is not supported. */
@Nullable
TextComponent getTextComponent();
/** /**
* Returns the component of this player for metadata output, or null if metadata is not supported. * Returns the component of this player for metadata output, or null if metadata is not supported.
*/ */

View File

@ -35,6 +35,7 @@ import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.MediaSourceFactory; import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.ExoTrackSelection; import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
@ -1002,6 +1003,12 @@ import java.util.concurrent.CopyOnWriteArraySet;
return 1; return 1;
} }
/** This method is not supported and returns an empty list. */
@Override
public ImmutableList<Cue> getCurrentCues() {
return ImmutableList.of();
}
private int getCurrentWindowIndexInternal() { private int getCurrentWindowIndexInternal() {
if (playbackInfo.timeline.isEmpty()) { if (playbackInfo.timeline.isEmpty()) {
return maskingWindowIndex; return maskingWindowIndex;

View File

@ -80,7 +80,7 @@ public class SimpleExoPlayer extends BasePlayer
implements ExoPlayer, implements ExoPlayer,
ExoPlayer.AudioComponent, ExoPlayer.AudioComponent,
Player.VideoComponent, Player.VideoComponent,
Player.TextComponent, ExoPlayer.TextComponent,
ExoPlayer.MetadataComponent, ExoPlayer.MetadataComponent,
Player.DeviceComponent { Player.DeviceComponent {

View File

@ -15,6 +15,8 @@
*/ */
package com.google.android.exoplayer2.ui; package com.google.android.exoplayer2.ui;
import static com.google.android.exoplayer2.Player.COMMAND_GET_TEXT;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
@ -56,7 +58,6 @@ import com.google.android.exoplayer2.metadata.flac.PictureFrame;
import com.google.android.exoplayer2.metadata.id3.ApicFrame; import com.google.android.exoplayer2.metadata.id3.ApicFrame;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionUtil; import com.google.android.exoplayer2.trackselection.TrackSelectionUtil;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
@ -562,7 +563,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
oldPlayer.removeListener(componentListener); oldPlayer.removeListener(componentListener);
@Nullable Player.VideoComponent oldVideoComponent = oldPlayer.getVideoComponent(); @Nullable Player.VideoComponent oldVideoComponent = oldPlayer.getVideoComponent();
if (oldVideoComponent != null) { if (oldVideoComponent != null) {
oldVideoComponent.removeVideoListener(componentListener);
if (surfaceView instanceof TextureView) { if (surfaceView instanceof TextureView) {
oldVideoComponent.clearVideoTextureView((TextureView) surfaceView); oldVideoComponent.clearVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalGLSurfaceView) { } else if (surfaceView instanceof SphericalGLSurfaceView) {
@ -571,10 +571,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
oldVideoComponent.clearVideoSurfaceView((SurfaceView) surfaceView); oldVideoComponent.clearVideoSurfaceView((SurfaceView) surfaceView);
} }
} }
@Nullable Player.TextComponent oldTextComponent = oldPlayer.getTextComponent();
if (oldTextComponent != null) {
oldTextComponent.removeTextOutput(componentListener);
}
} }
if (subtitleView != null) { if (subtitleView != null) {
subtitleView.setCues(null); subtitleView.setCues(null);
@ -598,12 +594,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
} }
newVideoComponent.addVideoListener(componentListener); newVideoComponent.addVideoListener(componentListener);
} }
@Nullable Player.TextComponent newTextComponent = player.getTextComponent(); if (subtitleView != null && player.isCommandAvailable(COMMAND_GET_TEXT)) {
if (newTextComponent != null) { subtitleView.setCues(player.getCurrentCues());
newTextComponent.addTextOutput(componentListener);
if (subtitleView != null) {
subtitleView.setCues(newTextComponent.getCurrentCues());
}
} }
player.addListener(componentListener); player.addListener(componentListener);
maybeShowController(false); maybeShowController(false);
@ -1491,8 +1483,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
} }
private final class ComponentListener private final class ComponentListener
implements Player.EventListener, implements Player.Listener,
TextOutput,
VideoListener, VideoListener,
OnLayoutChangeListener, OnLayoutChangeListener,
SingleTapListener, SingleTapListener,

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ui; package com.google.android.exoplayer2.ui;
import static com.google.android.exoplayer2.Player.COMMAND_GET_TEXT;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -571,7 +572,6 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
oldPlayer.removeListener(componentListener); oldPlayer.removeListener(componentListener);
@Nullable Player.VideoComponent oldVideoComponent = oldPlayer.getVideoComponent(); @Nullable Player.VideoComponent oldVideoComponent = oldPlayer.getVideoComponent();
if (oldVideoComponent != null) { if (oldVideoComponent != null) {
oldVideoComponent.removeVideoListener(componentListener);
if (surfaceView instanceof TextureView) { if (surfaceView instanceof TextureView) {
oldVideoComponent.clearVideoTextureView((TextureView) surfaceView); oldVideoComponent.clearVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalGLSurfaceView) { } else if (surfaceView instanceof SphericalGLSurfaceView) {
@ -580,10 +580,6 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
oldVideoComponent.clearVideoSurfaceView((SurfaceView) surfaceView); oldVideoComponent.clearVideoSurfaceView((SurfaceView) surfaceView);
} }
} }
@Nullable Player.TextComponent oldTextComponent = oldPlayer.getTextComponent();
if (oldTextComponent != null) {
oldTextComponent.removeTextOutput(componentListener);
}
} }
if (subtitleView != null) { if (subtitleView != null) {
subtitleView.setCues(null); subtitleView.setCues(null);
@ -607,12 +603,8 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
} }
newVideoComponent.addVideoListener(componentListener); newVideoComponent.addVideoListener(componentListener);
} }
@Nullable Player.TextComponent newTextComponent = player.getTextComponent(); if (subtitleView != null && player.isCommandAvailable(COMMAND_GET_TEXT)) {
if (newTextComponent != null) { subtitleView.setCues(player.getCurrentCues());
newTextComponent.addTextOutput(componentListener);
if (subtitleView != null) {
subtitleView.setCues(newTextComponent.getCurrentCues());
}
} }
player.addListener(componentListener); player.addListener(componentListener);
maybeShowController(false); maybeShowController(false);

View File

@ -32,6 +32,7 @@ import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
@ -438,6 +439,11 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public List<Cue> getCurrentCues() {
throw new UnsupportedOperationException();
}
@Override @Override
public void setForegroundMode(boolean foregroundMode) { public void setForegroundMode(boolean foregroundMode) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();