Rename PlayerView to LegacyPlayerView in media3

The old name is kept in exoplayer2.

PiperOrigin-RevId: 417378759
This commit is contained in:
ibaker 2021-12-20 12:22:32 +00:00 committed by tonihei
parent d0041d4666
commit 9dae5fd2c0
13 changed files with 192 additions and 178 deletions

View File

@ -44,7 +44,7 @@ import androidx.media3.exoplayer.drm.FrameworkMediaDrm;
import androidx.media3.exoplayer.drm.HttpMediaDrmCallback;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import androidx.media3.ui.PlayerControlView;
import androidx.media3.ui.LegacyPlayerControlView;
import java.util.UUID;
/** Activity that demonstrates use of {@link SurfaceControl} with ExoPlayer. */
@ -61,7 +61,7 @@ public final class MainActivity extends Activity {
private static final String OWNER_EXTRA = "owner";
private boolean isOwner;
@Nullable private PlayerControlView playerControlView;
@Nullable private LegacyPlayerControlView playerControlView;
@Nullable private SurfaceView fullScreenView;
@Nullable private SurfaceView nonFullScreenView;
@Nullable private SurfaceView currentOutputView;
@ -146,7 +146,7 @@ public final class MainActivity extends Activity {
setCurrentOutputView(nonFullScreenView);
PlayerControlView playerControlView = Assertions.checkNotNull(this.playerControlView);
LegacyPlayerControlView playerControlView = Assertions.checkNotNull(this.playerControlView);
playerControlView.setPlayer(player);
playerControlView.show();
}

View File

@ -32,7 +32,7 @@
android:layout_weight="1"
android:columnCount="3"/>
<androidx.media3.ui.PlayerControlView
<androidx.media3.ui.LegacyPlayerControlView
android:id="@+id/player_control_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -104,20 +104,20 @@ gets from the libgav1 decoder:
* GL rendering using GL shader for color space conversion
* If you are using `ExoPlayer` with `PlayerView` or `StyledPlayerView`,
enable this option by setting `surface_type` of view to be
`video_decoder_gl_surface_view`.
* If you are using `ExoPlayer` with `LegacyPlayerView` or
`StyledPlayerView`, enable this option by setting `surface_type` of view
to be `video_decoder_gl_surface_view`.
* Otherwise, enable this option by sending `Libgav1VideoRenderer` a
message of type `Renderer.MSG_SET_VIDEO_OUTPUT`
with an instance of `VideoDecoderOutputBufferRenderer` as its object.
message of type `Renderer.MSG_SET_VIDEO_OUTPUT` with an instance of
`VideoDecoderOutputBufferRenderer` as its object.
`VideoDecoderGLSurfaceView` is the concrete
`VideoDecoderOutputBufferRenderer` implementation used by
`(Styled)PlayerView`.
* Native rendering using `ANativeWindow`
* If you are using `ExoPlayer` with `PlayerView` or `StyledPlayerView`,
this option is enabled by default.
* If you are using `ExoPlayer` with `LegacyPlayerView` or
`StyledPlayerView`, this option is enabled by default.
* Otherwise, enable this option by sending `Libgav1VideoRenderer` a
message of type `Renderer.MSG_SET_VIDEO_OUTPUT` with an instance of
`SurfaceView` as its object.

View File

@ -117,20 +117,20 @@ gets from the libvpx decoder:
* GL rendering using GL shader for color space conversion
* If you are using `ExoPlayer` with `PlayerView` or `StyledPlayerView`,
enable this option by setting `surface_type` of view to be
`video_decoder_gl_surface_view`.
* If you are using `ExoPlayer` with `LegacyPlayerView` or
`StyledPlayerView`, enable this option by setting `surface_type` of view
to be `video_decoder_gl_surface_view`.
* Otherwise, enable this option by sending `LibvpxVideoRenderer` a message
of type `Renderer.MSG_SET_VIDEO_OUTPUT` with an
instance of `VideoDecoderOutputBufferRenderer` as its object.
of type `Renderer.MSG_SET_VIDEO_OUTPUT` with an instance of
`VideoDecoderOutputBufferRenderer` as its object.
`VideoDecoderGLSurfaceView` is the concrete
`VideoDecoderOutputBufferRenderer` implementation used by
`(Styled)PlayerView`.
* Native rendering using `ANativeWindow`
* If you are using `ExoPlayer` with `PlayerView` or `StyledPlayerView`,
this option is enabled by default.
* If you are using `ExoPlayer` with `LegacyPlayerView` or
`StyledPlayerView`, this option is enabled by default.
* Otherwise, enable this option by sending `LibvpxVideoRenderer` a message
of type `Renderer.MSG_SET_VIDEO_OUTPUT` with an instance of
`SurfaceView` as its object.

View File

@ -1,6 +1,6 @@
# Proguard rules specific to the UI module.
# Constructor method accessed via reflection in StyledPlayerView and PlayerView
# Constructor method accessed via reflection in StyledPlayerView and LegacyPlayerView
-dontnote androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView
-keepclassmembers class androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView {
<init>(android.content.Context);

View File

@ -67,13 +67,13 @@ import java.util.concurrent.CopyOnWriteArrayList;
/**
* A view for controlling {@link Player} instances.
*
* <p>A PlayerControlView can be customized by setting attributes (or calling corresponding
* <p>A LegacyPlayerControlView can be customized by setting attributes (or calling corresponding
* methods), overriding drawables, overriding the view's layout file, or by specifying a custom view
* layout file.
*
* <h2>Attributes</h2>
*
* The following attributes can be set on a PlayerControlView when used in a layout XML file:
* The following attributes can be set on a LegacyPlayerControlView when used in a layout XML file:
*
* <ul>
* <li><b>{@code show_timeout}</b> - The time between the last user interaction and the controls
@ -108,7 +108,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* or {@code one|all}.
* <ul>
* <li>Corresponding method: {@link #setRepeatToggleModes(int)}
* <li>Default: {@link PlayerControlView#DEFAULT_REPEAT_TOGGLE_MODES}
* <li>Default: {@link LegacyPlayerControlView#DEFAULT_REPEAT_TOGGLE_MODES}
* </ul>
* <li><b>{@code show_shuffle_button}</b> - Whether the shuffle button is shown.
* <ul>
@ -125,44 +125,45 @@ import java.util.concurrent.CopyOnWriteArrayList;
* below for more details.
* <ul>
* <li>Corresponding method: None
* <li>Default: {@code R.layout.exo_player_control_view}
* <li>Default: {@code R.layout.exo_legacy_player_control_view}
* </ul>
* <li>All attributes that can be set on {@link DefaultTimeBar} can also be set on a
* PlayerControlView, and will be propagated to the inflated {@link DefaultTimeBar} unless the
* layout is overridden to specify a custom {@code exo_progress} (see below).
* LegacyPlayerControlView, and will be propagated to the inflated {@link DefaultTimeBar}
* unless the layout is overridden to specify a custom {@code exo_progress} (see below).
* </ul>
*
* <h2>Overriding drawables</h2>
*
* The drawables used by PlayerControlView (with its default layout file) can be overridden by
* The drawables used by LegacyPlayerControlView (with its default layout file) can be overridden by
* drawables with the same names defined in your application. The drawables that can be overridden
* are:
*
* <ul>
* <li><b>{@code exo_controls_play}</b> - The play icon.
* <li><b>{@code exo_controls_pause}</b> - The pause icon.
* <li><b>{@code exo_controls_rewind}</b> - The rewind icon.
* <li><b>{@code exo_controls_fastforward}</b> - The fast forward icon.
* <li><b>{@code exo_controls_previous}</b> - The previous icon.
* <li><b>{@code exo_controls_next}</b> - The next icon.
* <li><b>{@code exo_controls_repeat_off}</b> - The repeat icon for {@link
* <li><b>{@code exo_legacy_controls_play}</b> - The play icon.
* <li><b>{@code exo_legacy_controls_pause}</b> - The pause icon.
* <li><b>{@code exo_legacy_controls_rewind}</b> - The rewind icon.
* <li><b>{@code exo_legacy_controls_fastforward}</b> - The fast forward icon.
* <li><b>{@code exo_legacy_controls_previous}</b> - The previous icon.
* <li><b>{@code exo_legacy_controls_next}</b> - The next icon.
* <li><b>{@code exo_legacy_controls_repeat_off}</b> - The repeat icon for {@link
* Player#REPEAT_MODE_OFF}.
* <li><b>{@code exo_controls_repeat_one}</b> - The repeat icon for {@link
* <li><b>{@code exo_legacy_controls_repeat_one}</b> - The repeat icon for {@link
* Player#REPEAT_MODE_ONE}.
* <li><b>{@code exo_controls_repeat_all}</b> - The repeat icon for {@link
* <li><b>{@code exo_legacy_controls_repeat_all}</b> - The repeat icon for {@link
* Player#REPEAT_MODE_ALL}.
* <li><b>{@code exo_controls_shuffle_off}</b> - The shuffle icon when shuffling is disabled.
* <li><b>{@code exo_controls_shuffle_on}</b> - The shuffle icon when shuffling is enabled.
* <li><b>{@code exo_controls_vr}</b> - The VR icon.
* <li><b>{@code exo_legacy_controls_shuffle_off}</b> - The shuffle icon when shuffling is
* disabled.
* <li><b>{@code exo_legacy_controls_shuffle_on}</b> - The shuffle icon when shuffling is enabled.
* <li><b>{@code exo_legacy_controls_vr}</b> - The VR icon.
* </ul>
*
* <h2>Overriding the layout file</h2>
*
* To customize the layout of PlayerControlView throughout your app, or just for certain
* configurations, you can define {@code exo_player_control_view.xml} layout files in your
* To customize the layout of LegacyPlayerControlView throughout your app, or just for certain
* configurations, you can define {@code exo_legacy_player_control_view.xml} layout files in your
* application {@code res/layout*} directories. These layouts will override the one provided by the
* library, and will be inflated for use by PlayerControlView. The view identifies and binds its
* children by looking for the following ids:
* library, and will be inflated for use by LegacyPlayerControlView. The view identifies and binds
* its children by looking for the following ids:
*
* <ul>
* <li><b>{@code exo_play}</b> - The play button.
@ -192,19 +193,19 @@ import java.util.concurrent.CopyOnWriteArrayList;
* <li><b>{@code exo_repeat_toggle}</b> - The repeat toggle button.
* <ul>
* <li>Type: {@link ImageView}
* <li>Note: PlayerControlView will programmatically set the drawable on the repeat toggle
* button according to the player's current repeat mode. The drawables used are {@code
* exo_controls_repeat_off}, {@code exo_controls_repeat_one} and {@code
* exo_controls_repeat_all}. See the section above for information on overriding these
* drawables.
* <li>Note: LegacyPlayerControlView will programmatically set the drawable on the repeat
* toggle button according to the player's current repeat mode. The drawables used are
* {@code exo_legacy_controls_repeat_off}, {@code exo_legacy_controls_repeat_one} and
* {@code exo_legacy_controls_repeat_all}. See the section above for information on
* overriding these drawables.
* </ul>
* <li><b>{@code exo_shuffle}</b> - The shuffle button.
* <ul>
* <li>Type: {@link ImageView}
* <li>Note: PlayerControlView will programmatically set the drawable on the shuffle button
* according to the player's current repeat mode. The drawables used are {@code
* exo_controls_shuffle_off} and {@code exo_controls_shuffle_on}. See the section above
* for information on overriding these drawables.
* <li>Note: LegacyPlayerControlView will programmatically set the drawable on the shuffle
* button according to the player's current repeat mode. The drawables used are {@code
* exo_legacy_controls_shuffle_off} and {@code exo_legacy_controls_shuffle_on}. See the
* section above for information on overriding these drawables.
* </ul>
* <li><b>{@code exo_vr}</b> - The VR mode button.
* <ul>
@ -224,9 +225,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
* <li>Type: {@link View}
* </ul>
* <li><b>{@code exo_progress}</b> - Time bar that's updated during playback and allows seeking.
* {@link DefaultTimeBar} attributes set on the PlayerControlView will not be automatically
* propagated through to this instance. If a view exists with this id, any {@code
* exo_progress_placeholder} view will be ignored.
* {@link DefaultTimeBar} attributes set on the LegacyPlayerControlView will not be
* automatically propagated through to this instance. If a view exists with this id, any
* {@code exo_progress_placeholder} view will be ignored.
* <ul>
* <li>Type: {@link TimeBar}
* </ul>
@ -237,14 +238,15 @@ import java.util.concurrent.CopyOnWriteArrayList;
*
* <h2>Specifying a custom layout file</h2>
*
* Defining your own {@code exo_player_control_view.xml} is useful to customize the layout of
* PlayerControlView throughout your application. It's also possible to customize the layout for a
* single instance in a layout file. This is achieved by setting the {@code controller_layout_id}
* attribute on a PlayerControlView. This will cause the specified layout to be inflated instead of
* {@code exo_player_control_view.xml} for only the instance on which the attribute is set.
* Defining your own {@code exo_legacy_player_control_view.xml} is useful to customize the layout of
* LegacyPlayerControlView throughout your application. It's also possible to customize the layout
* for a single instance in a layout file. This is achieved by setting the {@code
* controller_layout_id} attribute on a LegacyPlayerControlView. This will cause the specified
* layout to be inflated instead of {@code exo_legacy_player_control_view.xml} for only the instance
* on which the attribute is set.
*/
@UnstableApi
public class PlayerControlView extends FrameLayout {
public class LegacyPlayerControlView extends FrameLayout {
static {
MediaLibraryInfo.registerModule("media3.ui");
@ -344,15 +346,15 @@ public class PlayerControlView extends FrameLayout {
private long currentPosition;
private long currentBufferedPosition;
public PlayerControlView(Context context) {
public LegacyPlayerControlView(Context context) {
this(context, /* attrs= */ null);
}
public PlayerControlView(Context context, @Nullable AttributeSet attrs) {
public LegacyPlayerControlView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, /* defStyleAttr= */ 0);
}
public PlayerControlView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public LegacyPlayerControlView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, attrs);
}
@ -361,13 +363,13 @@ public class PlayerControlView extends FrameLayout {
"nullness:method.invocation",
"nullness:methodref.receiver.bound"
})
public PlayerControlView(
public LegacyPlayerControlView(
Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
@Nullable AttributeSet playbackAttrs) {
super(context, attrs, defStyleAttr);
int controllerLayoutId = R.layout.exo_player_control_view;
int controllerLayoutId = R.layout.exo_legacy_player_control_view;
showTimeoutMs = DEFAULT_SHOW_TIMEOUT_MS;
repeatToggleModes = DEFAULT_REPEAT_TOGGLE_MODES;
timeBarMinUpdateIntervalMs = DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS;
@ -382,26 +384,32 @@ public class PlayerControlView extends FrameLayout {
context
.getTheme()
.obtainStyledAttributes(
playbackAttrs, R.styleable.PlayerControlView, defStyleAttr, /* defStyleRes= */ 0);
playbackAttrs,
R.styleable.LegacyPlayerControlView,
defStyleAttr,
/* defStyleRes= */ 0);
try {
showTimeoutMs = a.getInt(R.styleable.PlayerControlView_show_timeout, showTimeoutMs);
showTimeoutMs = a.getInt(R.styleable.LegacyPlayerControlView_show_timeout, showTimeoutMs);
controllerLayoutId =
a.getResourceId(R.styleable.PlayerControlView_controller_layout_id, controllerLayoutId);
a.getResourceId(
R.styleable.LegacyPlayerControlView_controller_layout_id, controllerLayoutId);
repeatToggleModes = getRepeatToggleModes(a, repeatToggleModes);
showRewindButton =
a.getBoolean(R.styleable.PlayerControlView_show_rewind_button, showRewindButton);
a.getBoolean(R.styleable.LegacyPlayerControlView_show_rewind_button, showRewindButton);
showFastForwardButton =
a.getBoolean(
R.styleable.PlayerControlView_show_fastforward_button, showFastForwardButton);
R.styleable.LegacyPlayerControlView_show_fastforward_button, showFastForwardButton);
showPreviousButton =
a.getBoolean(R.styleable.PlayerControlView_show_previous_button, showPreviousButton);
a.getBoolean(
R.styleable.LegacyPlayerControlView_show_previous_button, showPreviousButton);
showNextButton =
a.getBoolean(R.styleable.PlayerControlView_show_next_button, showNextButton);
a.getBoolean(R.styleable.LegacyPlayerControlView_show_next_button, showNextButton);
showShuffleButton =
a.getBoolean(R.styleable.PlayerControlView_show_shuffle_button, showShuffleButton);
a.getBoolean(
R.styleable.LegacyPlayerControlView_show_shuffle_button, showShuffleButton);
setTimeBarMinUpdateInterval(
a.getInt(
R.styleable.PlayerControlView_time_bar_min_update_interval,
R.styleable.LegacyPlayerControlView_time_bar_min_update_interval,
timeBarMinUpdateIntervalMs));
} finally {
a.recycle();
@ -490,11 +498,11 @@ public class PlayerControlView extends FrameLayout {
buttonAlphaDisabled =
(float) resources.getInteger(R.integer.exo_media_button_opacity_percentage_disabled) / 100;
repeatOffButtonDrawable = resources.getDrawable(R.drawable.exo_controls_repeat_off);
repeatOneButtonDrawable = resources.getDrawable(R.drawable.exo_controls_repeat_one);
repeatAllButtonDrawable = resources.getDrawable(R.drawable.exo_controls_repeat_all);
shuffleOnButtonDrawable = resources.getDrawable(R.drawable.exo_controls_shuffle_on);
shuffleOffButtonDrawable = resources.getDrawable(R.drawable.exo_controls_shuffle_off);
repeatOffButtonDrawable = resources.getDrawable(R.drawable.exo_legacy_controls_repeat_off);
repeatOneButtonDrawable = resources.getDrawable(R.drawable.exo_legacy_controls_repeat_one);
repeatAllButtonDrawable = resources.getDrawable(R.drawable.exo_legacy_controls_repeat_all);
shuffleOnButtonDrawable = resources.getDrawable(R.drawable.exo_legacy_controls_shuffle_on);
shuffleOffButtonDrawable = resources.getDrawable(R.drawable.exo_legacy_controls_shuffle_off);
repeatOffButtonContentDescription =
resources.getString(R.string.exo_controls_repeat_off_description);
repeatOneButtonContentDescription =
@ -1273,7 +1281,7 @@ public class PlayerControlView extends FrameLayout {
@SuppressWarnings("ResourceType")
private static @RepeatModeUtil.RepeatToggleModes int getRepeatToggleModes(
TypedArray a, @RepeatModeUtil.RepeatToggleModes int defaultValue) {
return a.getInt(R.styleable.PlayerControlView_repeat_toggle_modes, defaultValue);
return a.getInt(R.styleable.LegacyPlayerControlView_repeat_toggle_modes, defaultValue);
}
private final class ComponentListener
@ -1332,7 +1340,7 @@ public class PlayerControlView extends FrameLayout {
@Override
public void onClick(View view) {
Player player = PlayerControlView.this.player;
Player player = LegacyPlayerControlView.this.player;
if (player == null) {
return;
}

View File

@ -74,15 +74,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/**
* A high level view for {@link Player} media playbacks. It displays video, subtitles and album art
* during playback, and displays playback controls using a {@link PlayerControlView}.
* during playback, and displays playback controls using a {@link LegacyPlayerControlView}.
*
* <p>A PlayerView can be customized by setting attributes (or calling corresponding methods),
* <p>A LegacyPlayerView can be customized by setting attributes (or calling corresponding methods),
* overriding drawables, overriding the view's layout file, or by specifying a custom view layout
* file.
*
* <h2>Attributes</h2>
*
* The following attributes can be set on a PlayerView when used in a layout XML file:
* The following attributes can be set on a LegacyPlayerView when used in a layout XML file:
*
* <ul>
* <li><b>{@code use_artwork}</b> - Whether artwork is used if available in audio streams.
@ -158,33 +158,33 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* for more details.
* <ul>
* <li>Corresponding method: None
* <li>Default: {@code R.layout.exo_player_view}
* <li>Default: {@code R.layout.exo_legacy_player_view}
* </ul>
* <li><b>{@code controller_layout_id}</b> - Specifies the id of the layout resource to be
* inflated by the child {@link PlayerControlView}. See below for more details.
* inflated by the child {@link LegacyPlayerControlView}. See below for more details.
* <ul>
* <li>Corresponding method: None
* <li>Default: {@code R.layout.exo_player_control_view}
* <li>Default: {@code R.layout.exo_legacy_player_control_view}
* </ul>
* <li>All attributes that can be set on {@link PlayerControlView} and {@link DefaultTimeBar} can
* also be set on a PlayerView, and will be propagated to the inflated {@link
* PlayerControlView} unless the layout is overridden to specify a custom {@code
* exo_controller} (see below).
* <li>All attributes that can be set on {@link LegacyPlayerControlView} and {@link
* DefaultTimeBar} can also be set on a LegacyPlayerView, and will be propagated to the
* inflated {@link LegacyPlayerControlView} unless the layout is overridden to specify a
* custom {@code exo_controller} (see below).
* </ul>
*
* <h2>Overriding drawables</h2>
*
* The drawables used by {@link PlayerControlView} (with its default layout file) can be overridden
* by drawables with the same names defined in your application. See the {@link PlayerControlView}
* documentation for a list of drawables that can be overridden.
* The drawables used by {@link LegacyPlayerControlView} (with its default layout file) can be
* overridden by drawables with the same names defined in your application. See the {@link
* LegacyPlayerControlView} documentation for a list of drawables that can be overridden.
*
* <h2>Overriding the layout file</h2>
*
* To customize the layout of PlayerView throughout your app, or just for certain configurations,
* you can define {@code exo_player_view.xml} layout files in your application {@code res/layout*}
* directories. These layouts will override the one provided by the library, and will be inflated
* for use by PlayerView. The view identifies and binds its children by looking for the following
* ids:
* To customize the layout of LegacyPlayerView throughout your app, or just for certain
* configurations, you can define {@code exo_legacy_player_view.xml} layout files in your
* application {@code res/layout*} directories. These layouts will override the one provided by the
* library, and will be inflated for use by LegacyPlayerView. The view identifies and binds its
* children by looking for the following ids:
*
* <ul>
* <li><b>{@code exo_content_frame}</b> - A frame whose aspect ratio is resized based on the video
@ -218,17 +218,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* <li>Type: {@link TextView}
* </ul>
* <li><b>{@code exo_controller_placeholder}</b> - A placeholder that's replaced with the inflated
* {@link PlayerControlView}. Ignored if an {@code exo_controller} view exists.
* {@link LegacyPlayerControlView}. Ignored if an {@code exo_controller} view exists.
* <ul>
* <li>Type: {@link View}
* </ul>
* <li><b>{@code exo_controller}</b> - An already inflated {@link PlayerControlView}. Allows use
* of a custom extension of {@link PlayerControlView}. {@link PlayerControlView} and {@link
* DefaultTimeBar} attributes set on the PlayerView will not be automatically propagated
* through to this instance. If a view exists with this id, any {@code
* exo_controller_placeholder} view will be ignored.
* <li><b>{@code exo_controller}</b> - An already inflated {@link LegacyPlayerControlView}. Allows
* use of a custom extension of {@link LegacyPlayerControlView}. {@link
* LegacyPlayerControlView} and {@link DefaultTimeBar} attributes set on the LegacyPlayerView
* will not be automatically propagated through to this instance. If a view exists with this
* id, any {@code exo_controller_placeholder} view will be ignored.
* <ul>
* <li>Type: {@link PlayerControlView}
* <li>Type: {@link LegacyPlayerControlView}
* </ul>
* <li><b>{@code exo_ad_overlay}</b> - A {@link FrameLayout} positioned on top of the player which
* is used to show ad UI (if applicable).
@ -247,14 +247,14 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
*
* <h2>Specifying a custom layout file</h2>
*
* Defining your own {@code exo_player_view.xml} is useful to customize the layout of PlayerView
* throughout your application. It's also possible to customize the layout for a single instance in
* a layout file. This is achieved by setting the {@code player_layout_id} attribute on a
* PlayerView. This will cause the specified layout to be inflated instead of {@code
* exo_player_view.xml} for only the instance on which the attribute is set.
* Defining your own {@code exo_legacy_player_view.xml} is useful to customize the layout of
* LegacyPlayerView throughout your application. It's also possible to customize the layout for a
* single instance in a layout file. This is achieved by setting the {@code player_layout_id}
* attribute on a LegacyPlayerView. This will cause the specified layout to be inflated instead of
* {@code exo_legacy_player_view.xml} for only the instance on which the attribute is set.
*/
@UnstableApi
public class PlayerView extends FrameLayout implements AdViewProvider {
public class LegacyPlayerView extends FrameLayout implements AdViewProvider {
/**
* Determines when the buffering view is shown. One of {@link #SHOW_BUFFERING_NEVER}, {@link
@ -292,13 +292,13 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
@Nullable private final SubtitleView subtitleView;
@Nullable private final View bufferingView;
@Nullable private final TextView errorMessageView;
@Nullable private final PlayerControlView controller;
@Nullable private final LegacyPlayerControlView controller;
@Nullable private final FrameLayout adOverlayFrameLayout;
@Nullable private final FrameLayout overlayFrameLayout;
@Nullable private Player player;
private boolean useController;
@Nullable private PlayerControlView.VisibilityListener controllerVisibilityListener;
@Nullable private LegacyPlayerControlView.VisibilityListener controllerVisibilityListener;
private boolean useArtwork;
@Nullable private Drawable defaultArtwork;
private @ShowBuffering int showBuffering;
@ -314,16 +314,16 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
private static final int PICTURE_TYPE_FRONT_COVER = 3;
private static final int PICTURE_TYPE_NOT_SET = -1;
public PlayerView(Context context) {
public LegacyPlayerView(Context context) {
this(context, /* attrs= */ null);
}
public PlayerView(Context context, @Nullable AttributeSet attrs) {
public LegacyPlayerView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, /* defStyleAttr= */ 0);
}
@SuppressWarnings({"nullness:argument", "nullness:method.invocation"})
public PlayerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
public LegacyPlayerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
componentListener = new ComponentListener();
@ -352,13 +352,13 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
boolean shutterColorSet = false;
int shutterColor = 0;
int playerLayoutId = R.layout.exo_player_view;
int playerLayoutId = R.layout.exo_legacy_player_view;
boolean useArtwork = true;
int defaultArtworkId = 0;
boolean useController = true;
int surfaceType = SURFACE_TYPE_SURFACE_VIEW;
int resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT;
int controllerShowTimeoutMs = PlayerControlView.DEFAULT_SHOW_TIMEOUT_MS;
int controllerShowTimeoutMs = LegacyPlayerControlView.DEFAULT_SHOW_TIMEOUT_MS;
boolean controllerHideOnTouch = true;
boolean controllerAutoShow = true;
boolean controllerHideDuringAds = true;
@ -368,28 +368,32 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
context
.getTheme()
.obtainStyledAttributes(
attrs, R.styleable.PlayerView, defStyleAttr, /* defStyleRes= */ 0);
attrs, R.styleable.LegacyPlayerView, defStyleAttr, /* defStyleRes= */ 0);
try {
shutterColorSet = a.hasValue(R.styleable.PlayerView_shutter_background_color);
shutterColor = a.getColor(R.styleable.PlayerView_shutter_background_color, shutterColor);
playerLayoutId = a.getResourceId(R.styleable.PlayerView_player_layout_id, playerLayoutId);
useArtwork = a.getBoolean(R.styleable.PlayerView_use_artwork, useArtwork);
shutterColorSet = a.hasValue(R.styleable.LegacyPlayerView_shutter_background_color);
shutterColor =
a.getColor(R.styleable.LegacyPlayerView_shutter_background_color, shutterColor);
playerLayoutId =
a.getResourceId(R.styleable.LegacyPlayerView_player_layout_id, playerLayoutId);
useArtwork = a.getBoolean(R.styleable.LegacyPlayerView_use_artwork, useArtwork);
defaultArtworkId =
a.getResourceId(R.styleable.PlayerView_default_artwork, defaultArtworkId);
useController = a.getBoolean(R.styleable.PlayerView_use_controller, useController);
surfaceType = a.getInt(R.styleable.PlayerView_surface_type, surfaceType);
resizeMode = a.getInt(R.styleable.PlayerView_resize_mode, resizeMode);
a.getResourceId(R.styleable.LegacyPlayerView_default_artwork, defaultArtworkId);
useController = a.getBoolean(R.styleable.LegacyPlayerView_use_controller, useController);
surfaceType = a.getInt(R.styleable.LegacyPlayerView_surface_type, surfaceType);
resizeMode = a.getInt(R.styleable.LegacyPlayerView_resize_mode, resizeMode);
controllerShowTimeoutMs =
a.getInt(R.styleable.PlayerView_show_timeout, controllerShowTimeoutMs);
a.getInt(R.styleable.LegacyPlayerView_show_timeout, controllerShowTimeoutMs);
controllerHideOnTouch =
a.getBoolean(R.styleable.PlayerView_hide_on_touch, controllerHideOnTouch);
controllerAutoShow = a.getBoolean(R.styleable.PlayerView_auto_show, controllerAutoShow);
showBuffering = a.getInteger(R.styleable.PlayerView_show_buffering, showBuffering);
a.getBoolean(R.styleable.LegacyPlayerView_hide_on_touch, controllerHideOnTouch);
controllerAutoShow =
a.getBoolean(R.styleable.LegacyPlayerView_auto_show, controllerAutoShow);
showBuffering = a.getInteger(R.styleable.LegacyPlayerView_show_buffering, showBuffering);
keepContentOnPlayerReset =
a.getBoolean(
R.styleable.PlayerView_keep_content_on_player_reset, keepContentOnPlayerReset);
R.styleable.LegacyPlayerView_keep_content_on_player_reset,
keepContentOnPlayerReset);
controllerHideDuringAds =
a.getBoolean(R.styleable.PlayerView_hide_during_ads, controllerHideDuringAds);
a.getBoolean(R.styleable.LegacyPlayerView_hide_during_ads, controllerHideDuringAds);
} finally {
a.recycle();
}
@ -446,9 +450,9 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
break;
}
surfaceView.setLayoutParams(params);
// We don't want surfaceView to be clickable separately to the PlayerView itself, but we do
// want to register as an OnClickListener so that surfaceView implementations can propagate
// click events up to the PlayerView by calling their own performClick method.
// We don't want surfaceView to be clickable separately to the LegacyPlayerView itself, but we
// do want to register as an OnClickListener so that surfaceView implementations can propagate
// click events up to the LegacyPlayerView by calling their own performClick method.
surfaceView.setOnClickListener(componentListener);
surfaceView.setClickable(false);
contentFrame.addView(surfaceView, 0);
@ -491,14 +495,14 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
}
// Playback control view.
PlayerControlView customController = findViewById(R.id.exo_controller);
LegacyPlayerControlView customController = findViewById(R.id.exo_controller);
View controllerPlaceholder = findViewById(R.id.exo_controller_placeholder);
if (customController != null) {
this.controller = customController;
} else if (controllerPlaceholder != null) {
// Propagate attrs as playbackAttrs so that PlayerControlView's custom attributes are
// Propagate attrs as playbackAttrs so that LegacyPlayerControlView's custom attributes are
// transferred, but standard attributes (e.g. background) are not.
this.controller = new PlayerControlView(context, null, 0, attrs);
this.controller = new LegacyPlayerControlView(context, null, 0, attrs);
controller.setId(R.id.exo_controller);
controller.setLayoutParams(controllerPlaceholder.getLayoutParams());
ViewGroup parent = ((ViewGroup) controllerPlaceholder.getParent());
@ -528,7 +532,9 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
* @param newPlayerView The new view to attach to the player.
*/
public static void switchTargetView(
Player player, @Nullable PlayerView oldPlayerView, @Nullable PlayerView newPlayerView) {
Player player,
@Nullable LegacyPlayerView oldPlayerView,
@Nullable LegacyPlayerView newPlayerView) {
if (oldPlayerView == newPlayerView) {
return;
}
@ -554,10 +560,10 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
* Sets the {@link Player} to use.
*
* <p>To transition a {@link Player} from targeting one view to another, it's recommended to use
* {@link #switchTargetView(Player, PlayerView, PlayerView)} rather than this method. If you do
* wish to use this method directly, be sure to attach the player to the new view <em>before</em>
* calling {@code setPlayer(null)} to detach it from the old one. This ordering is significantly
* more efficient and may allow for more seamless transitions.
* {@link #switchTargetView(Player, LegacyPlayerView, LegacyPlayerView)} rather than this method.
* If you do wish to use this method directly, be sure to attach the player to the new view
* <em>before</em> calling {@code setPlayer(null)} to detach it from the old one. This ordering is
* significantly more efficient and may allow for more seamless transitions.
*
* @param player The {@link Player} to use, or {@code null} to detach the current player. Only
* players which are accessed on the main thread are supported ({@code
@ -908,13 +914,13 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
}
/**
* Sets the {@link PlayerControlView.VisibilityListener}.
* Sets the {@link LegacyPlayerControlView.VisibilityListener}.
*
* @param listener The listener to be notified about visibility changes, or null to remove the
* current listener.
*/
public void setControllerVisibilityListener(
@Nullable PlayerControlView.VisibilityListener listener) {
@Nullable LegacyPlayerControlView.VisibilityListener listener) {
Assertions.checkStateNotNull(controller);
if (this.controllerVisibilityListener == listener) {
return;
@ -1457,7 +1463,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
implements Player.Listener,
OnLayoutChangeListener,
OnClickListener,
PlayerControlView.VisibilityListener {
LegacyPlayerControlView.VisibilityListener {
private final Period period;
private @Nullable Object lastPeriodUidWithTracks;
@ -1492,7 +1498,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
// Suppress the update if transitioning to an unprepared period within the same window. This
// is necessary to avoid closing the shutter when such a transition occurs. See:
// https://github.com/google/ExoPlayer/issues/5507.
Player player = Assertions.checkNotNull(PlayerView.this.player);
Player player = Assertions.checkNotNull(LegacyPlayerView.this.player);
Timeline timeline = player.getCurrentTimeline();
if (timeline.isEmpty()) {
lastPeriodUidWithTracks = null;
@ -1562,7 +1568,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
toggleControllerVisibility();
}
// PlayerControlView.VisibilityListener implementation
// LegacyPlayerControlView.VisibilityListener implementation
@Override
public void onVisibilityChange(int visibility) {

View File

@ -24,7 +24,7 @@
<enum name="zoom" value="4"/>
</attr>
<!-- Must be kept in sync with PlayerView and StyledPlayerView -->
<!-- Must be kept in sync with LegacyPlayerView and StyledPlayerView -->
<attr name="surface_type" format="enum">
<enum name="none" value="0"/>
<enum name="surface_view" value="1"/>
@ -40,7 +40,7 @@
<flag name="all" value="2"/>
</attr>
<!-- PlayerView and StyledPlayerView attributes -->
<!-- LegacyPlayerView and StyledPlayerView attributes -->
<attr name="use_artwork" format="boolean"/>
<attr name="shutter_background_color" format="color"/>
<attr name="default_artwork" format="reference"/>
@ -56,7 +56,7 @@
<attr name="keep_content_on_player_reset" format="boolean"/>
<attr name="player_layout_id" format="reference"/>
<!-- PlayerControlView and StyledPlayerControlView attributes -->
<!-- LegacyPlayerControlView and StyledPlayerControlView attributes -->
<attr name="show_timeout" format="integer"/>
<attr name="show_rewind_button" format="boolean"/>
<attr name="show_fastforward_button" format="boolean"/>
@ -105,7 +105,7 @@
<attr name="surface_type"/>
<!-- AspectRatioFrameLayout attributes -->
<attr name="resize_mode"/>
<!-- PlayerControlView attributes -->
<!-- LegacyPlayerControlView attributes -->
<attr name="show_timeout"/>
<attr name="repeat_toggle_modes"/>
<attr name="show_shuffle_button"/>

View File

@ -15,7 +15,7 @@
-->
<resources>
<declare-styleable name="PlayerView">
<declare-styleable name="LegacyPlayerView">
<attr name="use_artwork"/>
<attr name="shutter_background_color"/>
<attr name="default_artwork"/>
@ -29,7 +29,7 @@
<attr name="surface_type"/>
<!-- AspectRatioFrameLayout attributes -->
<attr name="resize_mode"/>
<!-- PlayerControlView attributes -->
<!-- LegacyPlayerControlView attributes -->
<attr name="show_timeout"/>
<attr name="repeat_toggle_modes"/>
<attr name="show_shuffle_button"/>
@ -51,7 +51,7 @@
<attr name="played_ad_marker_color"/>
</declare-styleable>
<declare-styleable name="PlayerControlView">
<declare-styleable name="LegacyPlayerControlView">
<attr name="show_timeout"/>
<attr name="repeat_toggle_modes"/>
<attr name="show_rewind_button"/>

View File

@ -14,18 +14,18 @@
limitations under the License.
-->
<resources>
<drawable name="exo_controls_play">@drawable/exo_icon_play</drawable>
<drawable name="exo_controls_pause">@drawable/exo_icon_pause</drawable>
<drawable name="exo_controls_next">@drawable/exo_icon_next</drawable>
<drawable name="exo_controls_previous">@drawable/exo_icon_previous</drawable>
<drawable name="exo_controls_fastforward">@drawable/exo_icon_fastforward</drawable>
<drawable name="exo_controls_rewind">@drawable/exo_icon_rewind</drawable>
<drawable name="exo_controls_repeat_all">@drawable/exo_icon_repeat_all</drawable>
<drawable name="exo_controls_repeat_off">@drawable/exo_icon_repeat_off</drawable>
<drawable name="exo_controls_repeat_one">@drawable/exo_icon_repeat_one</drawable>
<drawable name="exo_controls_shuffle_off">@drawable/exo_icon_shuffle_off</drawable>
<drawable name="exo_controls_shuffle_on">@drawable/exo_icon_shuffle_on</drawable>
<drawable name="exo_controls_fullscreen_enter">@drawable/exo_icon_fullscreen_enter</drawable>
<drawable name="exo_controls_fullscreen_exit">@drawable/exo_icon_fullscreen_exit</drawable>
<drawable name="exo_controls_vr">@drawable/exo_icon_vr</drawable>
<drawable name="exo_legacy_controls_play">@drawable/exo_icon_play</drawable>
<drawable name="exo_legacy_controls_pause">@drawable/exo_icon_pause</drawable>
<drawable name="exo_legacy_controls_next">@drawable/exo_icon_next</drawable>
<drawable name="exo_legacy_controls_previous">@drawable/exo_icon_previous</drawable>
<drawable name="exo_legacy_controls_fastforward">@drawable/exo_icon_fastforward</drawable>
<drawable name="exo_legacy_controls_rewind">@drawable/exo_icon_rewind</drawable>
<drawable name="exo_legacy_controls_repeat_all">@drawable/exo_icon_repeat_all</drawable>
<drawable name="exo_legacy_controls_repeat_off">@drawable/exo_icon_repeat_off</drawable>
<drawable name="exo_legacy_controls_repeat_one">@drawable/exo_icon_repeat_one</drawable>
<drawable name="exo_legacy_controls_shuffle_off">@drawable/exo_icon_shuffle_off</drawable>
<drawable name="exo_legacy_controls_shuffle_on">@drawable/exo_icon_shuffle_on</drawable>
<drawable name="exo_legacy_controls_fullscreen_enter">@drawable/exo_icon_fullscreen_enter</drawable>
<drawable name="exo_legacy_controls_fullscreen_exit">@drawable/exo_icon_fullscreen_exit</drawable>
<drawable name="exo_legacy_controls_vr">@drawable/exo_icon_vr</drawable>
</resources>

View File

@ -22,37 +22,37 @@
</style>
<style name="ExoMediaButton.Previous">
<item name="android:src">@drawable/exo_controls_previous</item>
<item name="android:src">@drawable/exo_legacy_controls_previous</item>
<item name="android:contentDescription">@string/exo_controls_previous_description</item>
</style>
<style name="ExoMediaButton.Next">
<item name="android:src">@drawable/exo_controls_next</item>
<item name="android:src">@drawable/exo_legacy_controls_next</item>
<item name="android:contentDescription">@string/exo_controls_next_description</item>
</style>
<style name="ExoMediaButton.FastForward">
<item name="android:src">@drawable/exo_controls_fastforward</item>
<item name="android:src">@drawable/exo_legacy_controls_fastforward</item>
<item name="android:contentDescription">@string/exo_controls_fastforward_description</item>
</style>
<style name="ExoMediaButton.Rewind">
<item name="android:src">@drawable/exo_controls_rewind</item>
<item name="android:src">@drawable/exo_legacy_controls_rewind</item>
<item name="android:contentDescription">@string/exo_controls_rewind_description</item>
</style>
<style name="ExoMediaButton.Play">
<item name="android:src">@drawable/exo_controls_play</item>
<item name="android:src">@drawable/exo_legacy_controls_play</item>
<item name="android:contentDescription">@string/exo_controls_play_description</item>
</style>
<style name="ExoMediaButton.Pause">
<item name="android:src">@drawable/exo_controls_pause</item>
<item name="android:src">@drawable/exo_legacy_controls_pause</item>
<item name="android:contentDescription">@string/exo_controls_pause_description</item>
</style>
<style name="ExoMediaButton.VR">
<item name="android:src">@drawable/exo_controls_vr</item>
<item name="android:src">@drawable/exo_legacy_controls_vr</item>
<item name="android:contentDescription">@string/exo_controls_vr_description</item>
</style>
</resources>