mirror of
https://github.com/samsonjs/media.git
synced 2026-04-05 11:15:46 +00:00
Add IntDef for Player states.
PiperOrigin-RevId: 245925254
This commit is contained in:
parent
f64011ae04
commit
0bb32a8f09
27 changed files with 55 additions and 39 deletions
|
|
@ -255,7 +255,7 @@ import java.util.ArrayList;
|
|||
// Player.EventListener implementation.
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
updateCurrentItemIndex();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -627,7 +627,7 @@ public class PlayerActivity extends AppCompatActivity
|
|||
private class PlayerEventListener implements Player.EventListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (playbackState == Player.STATE_ENDED) {
|
||||
showControls();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public final class CastPlayer extends BasePlayer {
|
|||
private CastTimeline currentTimeline;
|
||||
private TrackGroupArray currentTrackGroups;
|
||||
private TrackSelectionArray currentTrackSelection;
|
||||
private int playbackState;
|
||||
@Player.State private int playbackState;
|
||||
private int repeatMode;
|
||||
private int currentWindowIndex;
|
||||
private boolean playWhenReady;
|
||||
|
|
@ -305,6 +305,7 @@ public final class CastPlayer extends BasePlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Player.State
|
||||
public int getPlaybackState() {
|
||||
return playbackState;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class FlacPlaybackTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (playbackState == Player.STATE_ENDED
|
||||
|| (playbackState == Player.STATE_IDLE && playbackException != null)) {
|
||||
player.release();
|
||||
|
|
|
|||
|
|
@ -963,7 +963,7 @@ public final class ImaAdsLoader
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (adsManager == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import java.util.ArrayList;
|
|||
private final Timeline timeline;
|
||||
|
||||
private boolean prepared;
|
||||
private int state;
|
||||
@Player.State private int state;
|
||||
private boolean playWhenReady;
|
||||
private long position;
|
||||
private long contentPosition;
|
||||
|
|
@ -96,8 +96,8 @@ import java.util.ArrayList;
|
|||
}
|
||||
}
|
||||
|
||||
/** Sets the state of this player with the given {@code STATE} constant. */
|
||||
public void setState(int state, boolean playWhenReady) {
|
||||
/** Sets the {@link Player.State} of this player. */
|
||||
public void setState(@Player.State int state, boolean playWhenReady) {
|
||||
boolean notify = this.state != state || this.playWhenReady != playWhenReady;
|
||||
this.state = state;
|
||||
this.playWhenReady = playWhenReady;
|
||||
|
|
@ -131,6 +131,7 @@ import java.util.ArrayList;
|
|||
}
|
||||
|
||||
@Override
|
||||
@Player.State
|
||||
public int getPlaybackState() {
|
||||
return state;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ package com.google.android.exoplayer2.ext.leanback;
|
|||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Pair;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import androidx.leanback.R;
|
||||
import androidx.leanback.media.PlaybackGlueHost;
|
||||
import androidx.leanback.media.PlayerAdapter;
|
||||
import androidx.leanback.media.SurfaceHolderGlueHost;
|
||||
import android.util.Pair;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ControlDispatcher;
|
||||
import com.google.android.exoplayer2.DefaultControlDispatcher;
|
||||
|
|
@ -271,7 +271,7 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab
|
|||
// Player.EventListener implementation.
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
notifyStateChanged();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -994,7 +994,7 @@ public final class MediaSessionConnector {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
invalidateMediaSessionPlaybackState();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class OpusPlaybackTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (playbackState == Player.STATE_ENDED
|
||||
|| (playbackState == Player.STATE_IDLE && playbackException != null)) {
|
||||
player.release();
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public class VpxPlaybackTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (playbackState == Player.STATE_ENDED
|
||||
|| (playbackState == Player.STATE_IDLE && playbackException != null)) {
|
||||
player.release();
|
||||
|
|
|
|||
|
|
@ -193,6 +193,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
}
|
||||
|
||||
@Override
|
||||
@Player.State
|
||||
public int getPlaybackState() {
|
||||
return playbackInfo.playbackState;
|
||||
}
|
||||
|
|
@ -658,7 +659,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
}
|
||||
|
||||
private PlaybackInfo getResetPlaybackInfo(
|
||||
boolean resetPosition, boolean resetState, int playbackState) {
|
||||
boolean resetPosition, boolean resetState, @Player.State int playbackState) {
|
||||
if (resetPosition) {
|
||||
maskingWindowIndex = 0;
|
||||
maskingPeriodIndex = 0;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
|||
*/
|
||||
public final long contentPositionUs;
|
||||
/** The current playback state. One of the {@link Player}.STATE_ constants. */
|
||||
public final int playbackState;
|
||||
@Player.State public final int playbackState;
|
||||
/** Whether the player is currently loading. */
|
||||
public final boolean isLoading;
|
||||
/** The currently available track groups. */
|
||||
|
|
@ -128,7 +128,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
|||
MediaPeriodId periodId,
|
||||
long startPositionUs,
|
||||
long contentPositionUs,
|
||||
int playbackState,
|
||||
@Player.State int playbackState,
|
||||
boolean isLoading,
|
||||
TrackGroupArray trackGroups,
|
||||
TrackSelectorResult trackSelectorResult,
|
||||
|
|
|
|||
|
|
@ -361,9 +361,9 @@ public interface Player {
|
|||
* #getPlaybackState()} changes.
|
||||
*
|
||||
* @param playWhenReady Whether playback will proceed when ready.
|
||||
* @param playbackState One of the {@code STATE} constants.
|
||||
* @param playbackState The new {@link State playback state}.
|
||||
*/
|
||||
default void onPlayerStateChanged(boolean playWhenReady, int playbackState) {}
|
||||
default void onPlayerStateChanged(boolean playWhenReady, @State int playbackState) {}
|
||||
|
||||
/**
|
||||
* Called when the value of {@link #getRepeatMode()} changes.
|
||||
|
|
@ -443,6 +443,14 @@ public interface Player {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Playback state. One of {@link #STATE_IDLE}, {@link #STATE_BUFFERING}, {@link #STATE_READY} or
|
||||
* {@link #STATE_ENDED}.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({STATE_IDLE, STATE_BUFFERING, STATE_READY, STATE_ENDED})
|
||||
@interface State {}
|
||||
/**
|
||||
* The player does not have any media to play.
|
||||
*/
|
||||
|
|
@ -581,10 +589,11 @@ public interface Player {
|
|||
void removeListener(EventListener listener);
|
||||
|
||||
/**
|
||||
* Returns the current state of the player.
|
||||
* Returns the current {@link State playback state} of the player.
|
||||
*
|
||||
* @return One of the {@code STATE} constants defined in this interface.
|
||||
* @return The current {@link State playback state}.
|
||||
*/
|
||||
@State
|
||||
int getPlaybackState();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -873,6 +873,7 @@ public class SimpleExoPlayer extends BasePlayer
|
|||
}
|
||||
|
||||
@Override
|
||||
@Player.State
|
||||
public int getPlaybackState() {
|
||||
verifyApplicationThread();
|
||||
return player.getPlaybackState();
|
||||
|
|
|
|||
|
|
@ -464,7 +464,7 @@ public class AnalyticsCollector
|
|||
}
|
||||
|
||||
@Override
|
||||
public final void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public final void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
EventTime eventTime = generatePlayingMediaPeriodEventTime();
|
||||
for (AnalyticsListener listener : listeners) {
|
||||
listener.onPlayerStateChanged(eventTime, playWhenReady, playbackState);
|
||||
|
|
|
|||
|
|
@ -127,10 +127,10 @@ public interface AnalyticsListener {
|
|||
*
|
||||
* @param eventTime The event time.
|
||||
* @param playWhenReady Whether the playback will proceed when ready.
|
||||
* @param playbackState One of the {@link Player}.STATE constants.
|
||||
* @param playbackState The new {@link Player.State playback state}.
|
||||
*/
|
||||
default void onPlayerStateChanged(
|
||||
EventTime eventTime, boolean playWhenReady, int playbackState) {}
|
||||
EventTime eventTime, boolean playWhenReady, @Player.State int playbackState) {}
|
||||
|
||||
/**
|
||||
* Called when the timeline changed.
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ public class EventLogger implements AnalyticsListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(EventTime eventTime, boolean playWhenReady, int state) {
|
||||
public void onPlayerStateChanged(
|
||||
EventTime eventTime, boolean playWhenReady, @Player.State int state) {
|
||||
logd(eventTime, "state", playWhenReady + ", " + getStateString(state));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -509,7 +509,7 @@ public final class ExoPlayerTest {
|
|||
private int currentPlaybackState = Player.STATE_IDLE;
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
currentPlaybackState = playbackState;
|
||||
}
|
||||
|
||||
|
|
@ -2113,7 +2113,7 @@ public final class ExoPlayerTest {
|
|||
final EventListener eventListener1 =
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
eventListener1States.add(playbackState);
|
||||
if (playbackState == Player.STATE_READY) {
|
||||
playerReference.get().stop(/* reset= */ true);
|
||||
|
|
@ -2123,7 +2123,7 @@ public final class ExoPlayerTest {
|
|||
final EventListener eventListener2 =
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
eventListener2States.add(playbackState);
|
||||
}
|
||||
};
|
||||
|
|
@ -2170,7 +2170,7 @@ public final class ExoPlayerTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
eventListenerPlayWhenReady.add(playWhenReady);
|
||||
eventListenerStates.add(playbackState);
|
||||
if (playbackState == Player.STATE_READY) {
|
||||
|
|
@ -2219,7 +2219,7 @@ public final class ExoPlayerTest {
|
|||
EventListener eventListener =
|
||||
new EventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (playbackState == Player.STATE_READY && clockAtStartMs.get() == C.TIME_UNSET) {
|
||||
clockAtStartMs.set(clock.elapsedRealtime());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -913,7 +913,7 @@ public final class AnalyticsCollectorTest {
|
|||
|
||||
@Override
|
||||
public void onPlayerStateChanged(
|
||||
EventTime eventTime, boolean playWhenReady, int playbackState) {
|
||||
EventTime eventTime, boolean playWhenReady, @Player.State int playbackState) {
|
||||
reportedEvents.add(new ReportedEvent(EVENT_PLAYER_STATE_CHANGED, eventTime));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class DebugTextViewHelper implements Player.EventListener, Runnable {
|
|||
// Player.EventListener implementation.
|
||||
|
||||
@Override
|
||||
public final void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public final void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1130,7 +1130,7 @@ public class PlayerControlView extends FrameLayout {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
updatePlayPauseButton();
|
||||
updateProgress();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1276,7 +1276,7 @@ public class PlayerNotificationManager {
|
|||
private class PlayerListener implements Player.EventListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (wasPlayWhenReady != playWhenReady || lastPlaybackState != playbackState) {
|
||||
startOrUpdateNotification();
|
||||
wasPlayWhenReady = playWhenReady;
|
||||
|
|
|
|||
|
|
@ -1427,7 +1427,7 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
|
|||
// Player.EventListener implementation
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
updateBuffering();
|
||||
updateErrorMessage();
|
||||
if (isPlayingAd() && controllerHideDuringAds) {
|
||||
|
|
|
|||
|
|
@ -669,7 +669,8 @@ public abstract class Action {
|
|||
player.addListener(
|
||||
new Player.EventListener() {
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(
|
||||
boolean playWhenReady, @Player.State int playbackState) {
|
||||
if (targetPlaybackState == playbackState) {
|
||||
player.removeListener(this);
|
||||
nextAction.schedule(player, trackSelector, surface, handler);
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
|||
|
||||
@Override
|
||||
public final void onPlayerStateChanged(
|
||||
EventTime eventTime, boolean playWhenReady, int playbackState) {
|
||||
EventTime eventTime, boolean playWhenReady, @Player.State int playbackState) {
|
||||
Log.d(tag, "state [" + playWhenReady + ", " + playbackState + "]");
|
||||
playerWasPrepared |= playbackState != Player.STATE_IDLE;
|
||||
if (playbackState == Player.STATE_ENDED
|
||||
|
|
|
|||
|
|
@ -589,7 +589,7 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
|
||||
public void onPlayerStateChanged(boolean playWhenReady, @Player.State int playbackState) {
|
||||
playerWasPrepared |= playbackState != Player.STATE_IDLE;
|
||||
if (playbackState == Player.STATE_ENDED
|
||||
|| (playbackState == Player.STATE_IDLE && playerWasPrepared)) {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Player.State
|
||||
public int getPlaybackState() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue