use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.
the class DefaultAnalyticsCollector method onVideoSizeChanged.
// Calling deprecated listener method.
@SuppressWarnings("deprecation")
@Override
public final void onVideoSizeChanged(VideoSize videoSize) {
EventTime eventTime = generateReadingMediaPeriodEventTime();
sendEvent(eventTime, AnalyticsListener.EVENT_VIDEO_SIZE_CHANGED, listener -> {
listener.onVideoSizeChanged(eventTime, videoSize);
listener.onVideoSizeChanged(eventTime, videoSize.width, videoSize.height, videoSize.unappliedRotationDegrees, videoSize.pixelWidthHeightRatio);
});
}
use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.
the class MetadataRetrieverTest method retrieveMetadata_heicMotionPhoto_outputsExpectedMetadata.
@Test
public void retrieveMetadata_heicMotionPhoto_outputsExpectedMetadata() throws Exception {
MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_MP.heic"));
MotionPhotoMetadata expectedMotionPhotoMetadata = new MotionPhotoMetadata(/* photoStartPosition= */
0, /* photoSize= */
28_853, /* photoPresentationTimestampUs= */
C.TIME_UNSET, /* videoStartPosition= */
28_869, /* videoSize= */
28_803);
ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
ShadowLooper.idleMainLooper();
TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
assertThat(trackGroups.length).isEqualTo(1);
assertThat(trackGroups.get(0).length).isEqualTo(1);
assertThat(trackGroups.get(0).getFormat(0).metadata.length()).isEqualTo(1);
assertThat(trackGroups.get(0).getFormat(0).metadata.get(0)).isEqualTo(expectedMotionPhotoMetadata);
}
use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.
the class MediaCodecVideoRendererTest method render_withMultipleQueued_sendsVideoSizeChangedWithCorrectPixelAspectRatioWhenMultipleQueued.
@Test
public void render_withMultipleQueued_sendsVideoSizeChangedWithCorrectPixelAspectRatioWhenMultipleQueued() throws Exception {
Format pAsp1 = VIDEO_H264.buildUpon().setPixelWidthHeightRatio(1f).build();
Format pAsp2 = VIDEO_H264.buildUpon().setPixelWidthHeightRatio(2f).build();
Format pAsp3 = VIDEO_H264.buildUpon().setPixelWidthHeightRatio(3f).build();
FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
true, /* individualAllocationSize= */
1024), /* mediaSourceEventDispatcher= */
null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
pAsp1, ImmutableList.of(oneByteSample(/* timeUs= */
0, C.BUFFER_FLAG_KEY_FRAME)));
fakeSampleStream.writeData(/* startPositionUs= */
0);
mediaCodecVideoRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { pAsp1, pAsp2, pAsp3 }, fakeSampleStream, /* positionUs= */
0, /* joining= */
false, /* mayRenderStartOfStream= */
false, /* startPositionUs= */
0, /* offsetUs */
0);
mediaCodecVideoRenderer.start();
mediaCodecVideoRenderer.render(/* positionUs= */
0, SystemClock.elapsedRealtime() * 1000);
mediaCodecVideoRenderer.render(/* positionUs= */
250, SystemClock.elapsedRealtime() * 1000);
fakeSampleStream.append(ImmutableList.of(format(pAsp2), oneByteSample(/* timeUs= */
5_000), oneByteSample(/* timeUs= */
10_000), format(pAsp3), oneByteSample(/* timeUs= */
15_000), oneByteSample(/* timeUs= */
20_000), END_OF_STREAM_ITEM));
fakeSampleStream.writeData(/* startPositionUs= */
5_000);
mediaCodecVideoRenderer.setCurrentStreamFinal();
int pos = 500;
do {
mediaCodecVideoRenderer.render(/* positionUs= */
pos, SystemClock.elapsedRealtime() * 1000);
pos += 250;
} while (!mediaCodecVideoRenderer.isEnded());
shadowOf(testMainLooper).idle();
ArgumentCaptor<VideoSize> videoSizesCaptor = ArgumentCaptor.forClass(VideoSize.class);
verify(eventListener, times(3)).onVideoSizeChanged(videoSizesCaptor.capture());
assertThat(videoSizesCaptor.getAllValues().stream().map(videoSize -> videoSize.pixelWidthHeightRatio).collect(Collectors.toList())).containsExactly(1f, 2f, 3f);
}
use of com.google.android.exoplayer2.video.VideoSize in project Slide by ccrama.
the class ExoVideoView method setupPlayer.
/**
* Initializes the view to render onto and the SimpleExoPlayer instance
*/
private void setupPlayer() {
// Create a view to render the video onto and an AspectRatioFrameLayout to size the video correctly
AspectRatioFrameLayout frame = new AspectRatioFrameLayout(context);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params.addRule(CENTER_IN_PARENT, TRUE);
frame.setLayoutParams(params);
frame.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
SurfaceView renderView = new SurfaceView(context);
frame.addView(renderView);
addView(frame);
// Create a track selector so we can set specific video quality for DASH
trackSelector = new DefaultTrackSelector(context);
if ((SettingValues.lowResAlways || (NetworkUtil.isConnected(context) && !NetworkUtil.isConnectedWifi(context) && SettingValues.lowResMobile)) && SettingValues.lqVideos) {
trackSelector.setParameters(trackSelector.buildUponParameters().setForceLowestBitrate(true));
} else {
trackSelector.setParameters(trackSelector.buildUponParameters().setForceHighestSupportedBitrate(true));
}
// Create the player, attach it to the view, make it repeat infinitely
player = new SimpleExoPlayer.Builder(context).setTrackSelector(trackSelector).build();
player.setVideoSurfaceView(renderView);
player.setRepeatMode(Player.REPEAT_MODE_ALL);
// Mute by default
player.setVolume(0f);
// Create audio focus helper
audioFocusHelper = new AudioFocusHelper(ContextCompat.getSystemService(context, AudioManager.class));
player.addListener(new Player.Listener() {
// Make the video use the correct aspect ratio
@Override
public void onVideoSizeChanged(@NonNull VideoSize videoSize) {
frame.setAspectRatio(videoSize.height == 0 || videoSize.width == 0 ? 1 : videoSize.width * videoSize.pixelWidthHeightRatio / videoSize.height);
}
// Logging
@Override
public void onTracksChanged(@NonNull TrackGroupArray trackGroups, @NonNull TrackSelectionArray trackSelections) {
StringBuilder toLog = new StringBuilder();
for (int i = 0; i < trackGroups.length; i++) {
for (int j = 0; j < trackGroups.get(i).length; j++) {
toLog.append("Format:\t").append(trackGroups.get(i).getFormat(j)).append("\n");
}
}
// FIXME: How do I make onTracksChanged work with ExoTrackSelection?
/*for (TrackSelection i : trackSelections.getAll()) {
if (i != null)
toLog.append("Selected format:\t").append(i.getSelectedFormat()).append("\n");
}*/
Log.v(LogUtil.getTag(), toLog.toString());
}
});
}
Aggregations