use of androidx.media3.common.VideoSize 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.VideoSize 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.VideoSize in project media by androidx.
the class MediaControllerListenerTest method onVideoSizeChanged.
@Test
public void onVideoSizeChanged() throws Exception {
VideoSize testVideoSize = new VideoSize(/* width= */
100, /* height= */
42, /* unappliedRotationDegrees= */
90, /* pixelWidthHeightRatio= */
1.2f);
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<VideoSize> videoSizeFromParamRef = new AtomicReference<>();
AtomicReference<VideoSize> videoSizeFromGetterRef = new AtomicReference<>();
Player.Listener listener = new Player.Listener() {
@Override
public void onVideoSizeChanged(VideoSize videoSize) {
videoSizeFromParamRef.set(videoSize);
videoSizeFromGetterRef.set(controller.getVideoSize());
latch.countDown();
}
};
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
remoteSession.getMockPlayer().notifyVideoSizeChanged(testVideoSize);
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(videoSizeFromParamRef.get()).isEqualTo(testVideoSize);
assertThat(videoSizeFromGetterRef.get()).isEqualTo(testVideoSize);
}
use of androidx.media3.common.VideoSize in project media by androidx.
the class FakeVideoRenderer method shouldProcessBuffer.
@Override
protected boolean shouldProcessBuffer(long bufferTimeUs, long playbackPositionUs) {
boolean shouldProcess = super.shouldProcessBuffer(bufferTimeUs, playbackPositionUs);
boolean shouldRenderFirstFrame = output != null && (!renderedFirstFrameAfterEnable ? (getState() == Renderer.STATE_STARTED || mayRenderFirstFrameAfterEnableIfNotStarted) : !renderedFirstFrameAfterReset);
shouldProcess |= shouldRenderFirstFrame && playbackPositionUs >= streamOffsetUs;
@Nullable Object output = this.output;
if (shouldProcess && !renderedFirstFrameAfterReset && output != null) {
@MonotonicNonNull Format format = Assertions.checkNotNull(this.format);
eventDispatcher.videoSizeChanged(new VideoSize(format.width, format.height, format.rotationDegrees, format.pixelWidthHeightRatio));
eventDispatcher.renderedFirstFrame(output);
renderedFirstFrameAfterReset = true;
renderedFirstFrameAfterEnable = true;
}
return shouldProcess;
}
use of androidx.media3.common.VideoSize in project media by androidx.
the class PlayerView method updateAspectRatio.
private void updateAspectRatio() {
VideoSize videoSize = player != null ? player.getVideoSize() : VideoSize.UNKNOWN;
int width = videoSize.width;
int height = videoSize.height;
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
float videoAspectRatio = (height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
if (surfaceView instanceof TextureView) {
// Try to apply rotation transformation when our surface is a TextureView.
if (videoAspectRatio > 0 && (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270)) {
// We will apply a rotation 90/270 degree to the output texture of the TextureView.
// In this case, the output video's width and height will be swapped.
videoAspectRatio = 1 / videoAspectRatio;
}
if (textureViewRotation != 0) {
surfaceView.removeOnLayoutChangeListener(componentListener);
}
textureViewRotation = unappliedRotationDegrees;
if (textureViewRotation != 0) {
// The texture view's dimensions might be changed after layout step.
// So add an OnLayoutChangeListener to apply rotation after layout step.
surfaceView.addOnLayoutChangeListener(componentListener);
}
applyTextureViewRotation((TextureView) surfaceView, textureViewRotation);
}
onContentAspectRatioChanged(contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio);
}
Aggregations