Move renderer from Player to ExoPlayer
The concept of Renderers is not needed in the Player interface. Move it to ExoPlayer. This should not break most users as they use SimpleExoPlayer. PiperOrigin-RevId: 359220977
This commit is contained in:
parent
716d003c84
commit
589f50fb22
@ -28,6 +28,9 @@
|
||||
* `DebugTextViewHelper` moved from `ui` package to `util` package.
|
||||
* Spherical UI components moved from `video.spherical` package to
|
||||
`ui.spherical` package, and made package private.
|
||||
* Core
|
||||
* Move `getRendererCount` and `getRendererType` methods from `Player` to
|
||||
`ExoPlayer`.
|
||||
* Remove deprecated symbols:
|
||||
* Remove `Player.DefaultEventListener`. Use `Player.EventListener`
|
||||
instead.
|
||||
|
@ -484,26 +484,6 @@ public final class CastPlayer extends BasePlayer {
|
||||
sessionManager.endCurrentSession(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRendererCount() {
|
||||
// We assume there are three renderers: video, audio, and text.
|
||||
return RENDERER_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRendererType(int index) {
|
||||
switch (index) {
|
||||
case RENDERER_INDEX_VIDEO:
|
||||
return C.TRACK_TYPE_VIDEO;
|
||||
case RENDERER_INDEX_AUDIO:
|
||||
return C.TRACK_TYPE_AUDIO;
|
||||
case RENDERER_INDEX_TEXT:
|
||||
return C.TRACK_TYPE_TEXT;
|
||||
default:
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRepeatMode(@RepeatMode int repeatMode) {
|
||||
if (remoteMediaClient == null) {
|
||||
|
@ -60,6 +60,7 @@ import com.google.android.exoplayer2.source.ads.AdsLoader.EventListener;
|
||||
import com.google.android.exoplayer2.source.ads.AdsLoader.OverlayInfo;
|
||||
import com.google.android.exoplayer2.source.ads.AdsMediaSource.AdLoadException;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionUtil;
|
||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
@ -700,12 +701,7 @@ import java.util.Map;
|
||||
|
||||
// Check for a selected track using an audio renderer.
|
||||
TrackSelectionArray trackSelections = player.getCurrentTrackSelections();
|
||||
for (int i = 0; i < player.getRendererCount() && i < trackSelections.length; i++) {
|
||||
if (player.getRendererType(i) == C.TRACK_TYPE_AUDIO && trackSelections.get(i) != null) {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return TrackSelectionUtil.hasTrackOfType(trackSelections, C.TRACK_TYPE_AUDIO) ? 100 : 0;
|
||||
}
|
||||
|
||||
private void handleAdEvent(AdEvent adEvent) {
|
||||
|
@ -55,11 +55,8 @@ import java.util.List;
|
||||
* which can be obtained by calling {@link #getCurrentTimeline()}.
|
||||
* <li>They can provide a {@link TrackGroupArray} defining the currently available tracks, which
|
||||
* can be obtained by calling {@link #getCurrentTrackGroups()}.
|
||||
* <li>They contain a number of renderers, each of which is able to render tracks of a single type
|
||||
* (e.g. audio, video or text). The number of renderers and their respective track types can
|
||||
* be obtained by calling {@link #getRendererCount()} and {@link #getRendererType(int)}.
|
||||
* <li>They can provide a {@link TrackSelectionArray} defining which of the currently available
|
||||
* tracks are selected to be rendered by each renderer. This can be obtained by calling {@link
|
||||
* tracks are selected to be rendered. This can be obtained by calling {@link
|
||||
* #getCurrentTrackSelections()}}.
|
||||
* </ul>
|
||||
*/
|
||||
@ -434,8 +431,10 @@ public interface Player {
|
||||
* other events that happen in the same {@link Looper} message queue iteration.
|
||||
*
|
||||
* @param trackGroups The available tracks. Never null, but may be of length zero.
|
||||
* @param trackSelections The track selections for each renderer. Never null and always of
|
||||
* length {@link #getRendererCount()}, but may contain null elements.
|
||||
* @param trackSelections The selected tracks. Never null, but may contain null elements. A
|
||||
* concrete implementation may include null elements if it has a fixed number of renderer
|
||||
* components, wishes to report a TrackSelection for each of them, and has one or more
|
||||
* renderer components that is not assigned any selected tracks.
|
||||
*/
|
||||
default void onTracksChanged(
|
||||
TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {}
|
||||
@ -1335,24 +1334,16 @@ public interface Player {
|
||||
*/
|
||||
void release();
|
||||
|
||||
/** Returns the number of renderers. */
|
||||
int getRendererCount();
|
||||
|
||||
/**
|
||||
* Returns the track type that the renderer at a given index handles.
|
||||
*
|
||||
* <p>For example, a video renderer will return {@link C#TRACK_TYPE_VIDEO}, an audio renderer will
|
||||
* return {@link C#TRACK_TYPE_AUDIO} and a text renderer will return {@link C#TRACK_TYPE_TEXT}.
|
||||
*
|
||||
* @param index The index of the renderer.
|
||||
* @return One of the {@code TRACK_TYPE_*} constants defined in {@link C}.
|
||||
*/
|
||||
int getRendererType(int index);
|
||||
|
||||
/** Returns the available track groups. */
|
||||
TrackGroupArray getCurrentTrackGroups();
|
||||
|
||||
/** Returns the current track selections for each renderer. */
|
||||
/**
|
||||
* Returns the current track selections.
|
||||
*
|
||||
* <p>A concrete implementation may include null elements if it has a fixed number of renderer
|
||||
* components, wishes to report a TrackSelection for each of them, and has one or more renderer
|
||||
* components that is not assigned any selected tracks.
|
||||
*/
|
||||
TrackSelectionArray getCurrentTrackSelections();
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,8 @@ import java.util.List;
|
||||
* provides default implementations for common media types ({@link MediaCodecVideoRenderer},
|
||||
* {@link MediaCodecAudioRenderer}, {@link TextRenderer} and {@link MetadataRenderer}). A
|
||||
* Renderer consumes media from the MediaSource being played. Renderers are injected when the
|
||||
* player is created.
|
||||
* player is created. The number of renderers and their respective track types can be obtained
|
||||
* by calling {@link #getRendererCount()} and {@link #getRendererType(int)}.
|
||||
* <li>A <b>{@link TrackSelector}</b> that selects tracks provided by the MediaSource to be
|
||||
* consumed by each of the available Renderers. The library provides a default implementation
|
||||
* ({@link DefaultTrackSelector}) suitable for most use cases. A TrackSelector is injected
|
||||
@ -449,6 +450,20 @@ public interface ExoPlayer extends Player {
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the number of renderers. */
|
||||
int getRendererCount();
|
||||
|
||||
/**
|
||||
* Returns the track type that the renderer at a given index handles.
|
||||
*
|
||||
* <p>For example, a video renderer will return {@link C#TRACK_TYPE_VIDEO}, an audio renderer will
|
||||
* return {@link C#TRACK_TYPE_AUDIO} and a text renderer will return {@link C#TRACK_TYPE_TEXT}.
|
||||
*
|
||||
* @param index The index of the renderer.
|
||||
* @return One of the {@code TRACK_TYPE_*} constants defined in {@link C}.
|
||||
*/
|
||||
int getRendererType(int index);
|
||||
|
||||
/**
|
||||
* Returns the track selector that this player uses, or null if track selection is not supported.
|
||||
*/
|
||||
|
@ -240,7 +240,7 @@ public interface Renderer extends PlayerMessage.Target {
|
||||
/**
|
||||
* Returns the track type that the renderer handles.
|
||||
*
|
||||
* @see Player#getRendererType(int)
|
||||
* @see ExoPlayer#getRendererType(int)
|
||||
* @return One of the {@code TRACK_TYPE_*} constants defined in {@link C}.
|
||||
*/
|
||||
int getTrackType();
|
||||
|
@ -19,6 +19,7 @@ import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride;
|
||||
import com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
/** Track selection related utility methods. */
|
||||
@ -97,4 +98,20 @@ public final class TrackSelectionUtil {
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/** Returns if a {@link TrackSelectionArray} has at least one track of the given type. */
|
||||
public static boolean hasTrackOfType(TrackSelectionArray trackSelections, int trackType) {
|
||||
for (int i = 0; i < trackSelections.length; i++) {
|
||||
@Nullable TrackSelection trackSelection = trackSelections.get(i);
|
||||
if (trackSelection == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < trackSelection.length(); j++) {
|
||||
if (MimeTypes.getTrackType(trackSelection.getFormat(j).sampleMimeType) == trackType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ import com.google.android.exoplayer2.source.ads.AdsLoader;
|
||||
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.TrackSelectionUtil;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
|
||||
import com.google.android.exoplayer2.ui.spherical.SingleTapListener;
|
||||
import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView;
|
||||
@ -1332,15 +1333,12 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
|
||||
closeShutter();
|
||||
}
|
||||
|
||||
TrackSelectionArray selections = player.getCurrentTrackSelections();
|
||||
for (int i = 0; i < selections.length; i++) {
|
||||
if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
|
||||
if (TrackSelectionUtil.hasTrackOfType(player.getCurrentTrackSelections(), C.TRACK_TYPE_VIDEO)) {
|
||||
// Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
|
||||
// onRenderedFirstFrame().
|
||||
hideArtwork();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Video disabled so the shutter must be closed.
|
||||
closeShutter();
|
||||
|
@ -60,6 +60,7 @@ import com.google.android.exoplayer2.source.ads.AdsLoader;
|
||||
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.TrackSelectionUtil;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
|
||||
import com.google.android.exoplayer2.ui.spherical.SingleTapListener;
|
||||
import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView;
|
||||
@ -1354,15 +1355,12 @@ public class StyledPlayerView extends FrameLayout implements AdsLoader.AdViewPro
|
||||
closeShutter();
|
||||
}
|
||||
|
||||
TrackSelectionArray selections = player.getCurrentTrackSelections();
|
||||
for (int i = 0; i < selections.length; i++) {
|
||||
if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
|
||||
if (TrackSelectionUtil.hasTrackOfType(player.getCurrentTrackSelections(), C.TRACK_TYPE_VIDEO)) {
|
||||
// Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
|
||||
// onRenderedFirstFrame().
|
||||
hideArtwork();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Video disabled so the shutter must be closed.
|
||||
closeShutter();
|
||||
|
Loading…
x
Reference in New Issue
Block a user