use of androidx.media3.common.Player.PlaybackSuppressionReason in project media by androidx.
the class ExoPlayerTest method audioFocusDenied.
@Test
public void audioFocusDenied() throws Exception {
ShadowAudioManager shadowAudioManager = shadowOf(context.getSystemService(AudioManager.class));
shadowAudioManager.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_FAILED);
PlayerStateGrabber playerStateGrabber = new PlayerStateGrabber();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */
true).play().waitForPlaybackState(Player.STATE_READY).executeRunnable(playerStateGrabber).build();
AtomicBoolean seenPlaybackSuppression = new AtomicBoolean();
Player.Listener listener = new Player.Listener() {
@Override
public void onPlaybackSuppressionReasonChanged(@Player.PlaybackSuppressionReason int playbackSuppressionReason) {
seenPlaybackSuppression.set(true);
}
};
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS);
assertThat(playerStateGrabber.playWhenReady).isFalse();
assertThat(seenPlaybackSuppression.get()).isFalse();
}
use of androidx.media3.common.Player.PlaybackSuppressionReason in project media by androidx.
the class ExoPlayerTest method simplePlaybackHasNoPlaybackSuppression.
@Test
public void simplePlaybackHasNoPlaybackSuppression() throws Exception {
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).play().waitForPlaybackState(Player.STATE_READY).pause().play().build();
AtomicBoolean seenPlaybackSuppression = new AtomicBoolean();
Player.Listener listener = new Player.Listener() {
@Override
public void onPlaybackSuppressionReasonChanged(@Player.PlaybackSuppressionReason int playbackSuppressionReason) {
seenPlaybackSuppression.set(true);
}
};
new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(seenPlaybackSuppression.get()).isFalse();
}
use of androidx.media3.common.Player.PlaybackSuppressionReason in project media by androidx.
the class PlayerInfo method fromBundle.
private static PlayerInfo fromBundle(Bundle bundle) {
@Nullable PlaybackException playerError = BundleableUtil.fromNullableBundle(PlaybackException.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYBACK_ERROR)));
int mediaItemTransitionReason = bundle.getInt(keyForField(FIELD_MEDIA_ITEM_TRANSITION_REASON), MEDIA_ITEM_TRANSITION_REASON_REPEAT);
SessionPositionInfo sessionPositionInfo = BundleableUtil.fromNullableBundle(SessionPositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_SESSION_POSITION_INFO)), SessionPositionInfo.DEFAULT);
PositionInfo oldPositionInfo = BundleableUtil.fromNullableBundle(PositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_OLD_POSITION_INFO)), SessionPositionInfo.DEFAULT_POSITION_INFO);
PositionInfo newPositionInfo = BundleableUtil.fromNullableBundle(PositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_NEW_POSITION_INFO)), SessionPositionInfo.DEFAULT_POSITION_INFO);
int discontinuityReason = bundle.getInt(keyForField(FIELD_DISCONTINUITY_REASON), DISCONTINUITY_REASON_AUTO_TRANSITION);
@Nullable Bundle playbackParametersBundle = bundle.getBundle(keyForField(FIELD_PLAYBACK_PARAMETERS));
PlaybackParameters playbackParameters = BundleableUtil.fromNullableBundle(PlaybackParameters.CREATOR, playbackParametersBundle, /* defaultValue= */
PlaybackParameters.DEFAULT);
@Player.RepeatMode int repeatMode = bundle.getInt(keyForField(FIELD_REPEAT_MODE), /* defaultValue= */
Player.REPEAT_MODE_OFF);
boolean shuffleModeEnabled = bundle.getBoolean(keyForField(FIELD_SHUFFLE_MODE_ENABLED), /* defaultValue= */
false);
Timeline timeline = BundleableUtil.fromNullableBundle(Timeline.CREATOR, bundle.getBundle(keyForField(FIELD_TIMELINE)), Timeline.EMPTY);
VideoSize videoSize = BundleableUtil.fromNullableBundle(VideoSize.CREATOR, bundle.getBundle(keyForField(FIELD_VIDEO_SIZE)), VideoSize.UNKNOWN);
MediaMetadata playlistMetadata = BundleableUtil.fromNullableBundle(MediaMetadata.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYLIST_METADATA)), MediaMetadata.EMPTY);
float volume = bundle.getFloat(keyForField(FIELD_VOLUME), /* defaultValue= */
1);
AudioAttributes audioAttributes = BundleableUtil.fromNullableBundle(AudioAttributes.CREATOR, bundle.getBundle(keyForField(FIELD_AUDIO_ATTRIBUTES)), /* defaultValue= */
AudioAttributes.DEFAULT);
List<Cue> cues = BundleableUtil.fromBundleNullableList(Cue.CREATOR, bundle.getParcelableArrayList(keyForField(FIELD_CUES)), /* defaultValue= */
ImmutableList.of());
@Nullable Bundle deviceInfoBundle = bundle.getBundle(keyForField(FIELD_DEVICE_INFO));
DeviceInfo deviceInfo = BundleableUtil.fromNullableBundle(DeviceInfo.CREATOR, deviceInfoBundle, /* defaultValue= */
DeviceInfo.UNKNOWN);
int deviceVolume = bundle.getInt(keyForField(FIELD_DEVICE_VOLUME), /* defaultValue= */
0);
boolean deviceMuted = bundle.getBoolean(keyForField(FIELD_DEVICE_MUTED), /* defaultValue= */
false);
boolean playWhenReady = bundle.getBoolean(keyForField(FIELD_PLAY_WHEN_READY), /* defaultValue= */
false);
int playWhenReadyChangedReason = bundle.getInt(keyForField(FIELD_PLAY_WHEN_READY_CHANGED_REASON), /* defaultValue= */
PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST);
@Player.PlaybackSuppressionReason int playbackSuppressionReason = bundle.getInt(keyForField(FIELD_PLAYBACK_SUPPRESSION_REASON), /* defaultValue= */
PLAYBACK_SUPPRESSION_REASON_NONE);
@Player.State int playbackState = bundle.getInt(keyForField(FIELD_PLAYBACK_STATE), /* defaultValue= */
STATE_IDLE);
boolean isPlaying = bundle.getBoolean(keyForField(FIELD_IS_PLAYING), /* defaultValue= */
false);
boolean isLoading = bundle.getBoolean(keyForField(FIELD_IS_LOADING), /* defaultValue= */
false);
MediaMetadata mediaMetadata = BundleableUtil.fromNullableBundle(MediaMetadata.CREATOR, bundle.getBundle(keyForField(FIELD_MEDIA_METADATA)), MediaMetadata.EMPTY);
long seekBackIncrementMs = bundle.getLong(keyForField(FIELD_SEEK_BACK_INCREMENT_MS), /* defaultValue= */
0);
long seekForwardIncrementMs = bundle.getLong(keyForField(FIELD_SEEK_FORWARD_INCREMENT_MS), /* defaultValue= */
0);
long maxSeekToPreviousPosition = bundle.getLong(keyForField(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS), /* defaultValue= */
0);
TrackSelectionParameters trackSelectionParameters = BundleableUtil.fromNullableBundle(TrackSelectionParameters.CREATOR, bundle.getBundle(keyForField(FIELD_TRACK_SELECTION_PARAMETERS)), TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
return new PlayerInfo(playerError, mediaItemTransitionReason, sessionPositionInfo, oldPositionInfo, newPositionInfo, discontinuityReason, playbackParameters, repeatMode, shuffleModeEnabled, videoSize, timeline, playlistMetadata, volume, audioAttributes, cues, deviceInfo, deviceVolume, deviceMuted, playWhenReady, playWhenReadyChangedReason, playbackSuppressionReason, playbackState, isPlaying, isLoading, mediaMetadata, seekBackIncrementMs, seekForwardIncrementMs, maxSeekToPreviousPosition, trackSelectionParameters);
}
use of androidx.media3.common.Player.PlaybackSuppressionReason in project media by androidx.
the class MediaControllerImplLegacy method createControllerInfo.
private static ControllerInfo createControllerInfo(QueueTimeline currentTimeline, MediaMetadata mediaMetadata, int currentMediaItemIndex, MediaMetadata playlistMetadata, @RepeatMode int repeatMode, boolean shuffleModeEnabled, SessionCommands availableSessionCommands, Commands availablePlayerCommands, ImmutableList<CommandButton> customLayout, @Nullable PlaybackException playerError, long durationMs, long currentPositionMs, long bufferedPositionMs, int bufferedPercentage, long totalBufferedDurationMs, boolean isPlayingAd, PlaybackParameters playbackParameters, AudioAttributes audioAttributes, boolean playWhenReady, int playbackState, boolean isPlaying, DeviceInfo deviceInfo, int deviceVolume, boolean deviceMuted, long seekBackIncrementMs, long seekForwardIncrementMs) {
@Nullable MediaItem currentMediaItem = currentTimeline.getMediaItemAt(currentMediaItemIndex);
PositionInfo positionInfo = createPositionInfo(currentMediaItemIndex, currentMediaItem, currentPositionMs);
SessionPositionInfo sessionPositionInfo = new SessionPositionInfo(/* positionInfo= */
positionInfo, /* isPlayingAd= */
isPlayingAd, /* eventTimeMs= */
C.TIME_UNSET, /* durationMs= */
durationMs, /* bufferedPositionMs= */
bufferedPositionMs, /* bufferedPercentage= */
bufferedPercentage, /* totalBufferedDurationMs= */
totalBufferedDurationMs, /* currentLiveOffsetMs= */
C.TIME_UNSET, /* contentDurationMs= */
durationMs, /* contentBufferedPositionMs= */
bufferedPositionMs);
PlayerInfo playerInfo = new PlayerInfo(/* playerError= */
playerError, /* mediaItemTransitionReason= */
PlayerInfo.MEDIA_ITEM_TRANSITION_REASON_DEFAULT, /* sessionPositionInfo= */
sessionPositionInfo, /* oldPositionInfo= */
SessionPositionInfo.DEFAULT_POSITION_INFO, /* newPositionInfo= */
SessionPositionInfo.DEFAULT_POSITION_INFO, /* discontinuityReason= */
PlayerInfo.DISCONTINUITY_REASON_DEFAULT, /* playbackParameters= */
playbackParameters, /* repeatMode= */
repeatMode, /* shuffleModeEnabled= */
shuffleModeEnabled, /* videoSize= */
VideoSize.UNKNOWN, /* timeline= */
currentTimeline, /* playlistMetadata= */
playlistMetadata, /* volume= */
1.0f, /* audioAttributes= */
audioAttributes, /* cues= */
Collections.emptyList(), /* deviceInfo= */
deviceInfo, /* deviceVolume= */
deviceVolume, /* deviceMuted= */
deviceMuted, /* playWhenReady= */
playWhenReady, /* playWhenReadyChangedReason= */
PlayerInfo.PLAY_WHEN_READY_CHANGE_REASON_DEFAULT, /* playbackSuppressionReason= */
Player.PLAYBACK_SUPPRESSION_REASON_NONE, /* playbackState= */
playbackState, /* isPlaying= */
isPlaying, /* isLoading= */
false, /* mediaMetadata= */
mediaMetadata, seekBackIncrementMs, seekForwardIncrementMs, /* maxSeekToPreviousPositionMs= */
0L, /* parameters= */
TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
return new ControllerInfo(playerInfo, availableSessionCommands, availablePlayerCommands, customLayout);
}
use of androidx.media3.common.Player.PlaybackSuppressionReason in project media by androidx.
the class MediaControllerListenerTest method onPlayWhenReadyChanged_isNotified.
@Test
public void onPlayWhenReadyChanged_isNotified() throws Exception {
boolean testPlayWhenReady = true;
@Player.PlayWhenReadyChangeReason int testReason = Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST;
@Player.PlaybackSuppressionReason int testSuppressionReason = Player.PLAYBACK_SUPPRESSION_REASON_NONE;
remoteSession.getMockPlayer().setPlayWhenReady(false, Player.PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS);
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
CountDownLatch latch = new CountDownLatch(2);
AtomicBoolean playWhenReadyRef = new AtomicBoolean();
AtomicInteger playWhenReadyReasonRef = new AtomicInteger();
AtomicInteger playbackSuppressionReasonRef = new AtomicInteger();
Player.Listener listener = new Player.Listener() {
@Override
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
playWhenReadyRef.set(playWhenReady);
playWhenReadyReasonRef.set(reason);
latch.countDown();
}
@Override
public void onPlaybackSuppressionReasonChanged(int playbackSuppressionReason) {
playbackSuppressionReasonRef.set(playbackSuppressionReason);
latch.countDown();
}
};
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
remoteSession.getMockPlayer().notifyPlayWhenReadyChanged(testPlayWhenReady, testReason);
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(playWhenReadyRef.get()).isEqualTo(testPlayWhenReady);
assertThat(playWhenReadyReasonRef.get()).isEqualTo(testReason);
assertThat(playbackSuppressionReasonRef.get()).isEqualTo(testSuppressionReason);
}
Aggregations