Search in sources :

Example 6 with VideoSize

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);
    });
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 7 with VideoSize

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);
}
Also used : MotionPhotoMetadata(com.google.android.exoplayer2.metadata.mp4.MotionPhotoMetadata) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Test(org.junit.Test)

Example 8 with VideoSize

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);
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) MediaFormat(android.media.MediaFormat) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) SystemClock(android.os.SystemClock) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Format(com.google.android.exoplayer2.Format) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) MediaCodecInfo(com.google.android.exoplayer2.mediacodec.MediaCodecInfo) ArgumentCaptor(org.mockito.ArgumentCaptor) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) ImmutableList(com.google.common.collect.ImmutableList) Handler(android.os.Handler) Looper(android.os.Looper) After(org.junit.After) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) MockitoJUnit(org.mockito.junit.MockitoJUnit) FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) Before(org.junit.Before) FakeSampleStreamItem.format(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.format) SurfaceTexture(android.graphics.SurfaceTexture) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) ShadowLooper(org.robolectric.shadows.ShadowLooper) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) Surface(android.view.Surface) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) Mockito.never(org.mockito.Mockito.never) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration) MediaCodecSelector(com.google.android.exoplayer2.mediacodec.MediaCodecSelector) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) MockitoRule(org.mockito.junit.MockitoRule) Renderer(com.google.android.exoplayer2.Renderer) Collections(java.util.Collections) MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 9 with VideoSize

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());
        }
    });
}
Also used : Player(com.google.android.exoplayer2.Player) SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) SimpleExoPlayer(com.google.android.exoplayer2.SimpleExoPlayer) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) VideoSize(com.google.android.exoplayer2.video.VideoSize) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) SurfaceView(android.view.SurfaceView)

Aggregations

VideoSize (com.google.android.exoplayer2.video.VideoSize)4 Nullable (androidx.annotation.Nullable)3 Format (com.google.android.exoplayer2.Format)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 TextureView (android.view.TextureView)2 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)2 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)2 SurfaceTexture (android.graphics.SurfaceTexture)1 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)1 CodecProfileLevel (android.media.MediaCodecInfo.CodecProfileLevel)1 MediaFormat (android.media.MediaFormat)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 SystemClock (android.os.SystemClock)1 Surface (android.view.Surface)1 SurfaceView (android.view.SurfaceView)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1