Search in sources :

Example 21 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class HlsMediaPeriod method onPrepared.

// HlsSampleStreamWrapper.Callback implementation.
@Override
public void onPrepared() {
    if (--pendingPrepareCount > 0) {
        return;
    }
    int totalTrackGroupCount = 0;
    for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
        totalTrackGroupCount += sampleStreamWrapper.getTrackGroups().length;
    }
    TrackGroup[] trackGroupArray = new TrackGroup[totalTrackGroupCount];
    int trackGroupIndex = 0;
    for (HlsSampleStreamWrapper sampleStreamWrapper : sampleStreamWrappers) {
        int wrapperTrackGroupCount = sampleStreamWrapper.getTrackGroups().length;
        for (int j = 0; j < wrapperTrackGroupCount; j++) {
            trackGroupArray[trackGroupIndex++] = sampleStreamWrapper.getTrackGroups().get(j);
        }
    }
    trackGroups = new TrackGroupArray(trackGroupArray);
    callback.onPrepared(this);
}
Also used : TrackGroup(androidx.media3.common.TrackGroup) TrackGroupArray(androidx.media3.common.TrackGroupArray)

Example 22 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class HlsSampleStreamWrapper method createTrackGroupArrayWithDrmInfo.

private TrackGroupArray createTrackGroupArrayWithDrmInfo(TrackGroup[] trackGroups) {
    for (int i = 0; i < trackGroups.length; i++) {
        TrackGroup trackGroup = trackGroups[i];
        Format[] exposedFormats = new Format[trackGroup.length];
        for (int j = 0; j < trackGroup.length; j++) {
            Format format = trackGroup.getFormat(j);
            exposedFormats[j] = format.copyWithCryptoType(drmSessionManager.getCryptoType(format));
        }
        trackGroups[i] = new TrackGroup(trackGroup.id, exposedFormats);
    }
    return new TrackGroupArray(trackGroups);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) TrackGroupArray(androidx.media3.common.TrackGroupArray)

Example 23 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class SsMediaPeriod method buildTrackGroups.

private static TrackGroupArray buildTrackGroups(SsManifest manifest, DrmSessionManager drmSessionManager) {
    TrackGroup[] trackGroups = new TrackGroup[manifest.streamElements.length];
    for (int i = 0; i < manifest.streamElements.length; i++) {
        Format[] manifestFormats = manifest.streamElements[i].formats;
        Format[] exposedFormats = new Format[manifestFormats.length];
        for (int j = 0; j < manifestFormats.length; j++) {
            Format manifestFormat = manifestFormats[j];
            exposedFormats[j] = manifestFormat.copyWithCryptoType(drmSessionManager.getCryptoType(manifestFormat));
        }
        trackGroups[i] = new TrackGroup(/* id= */
        Integer.toString(i), exposedFormats);
    }
    return new TrackGroupArray(trackGroups);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) TrackGroupArray(androidx.media3.common.TrackGroupArray)

Example 24 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class MediaPeriodAsserts method assertTrackGroups.

/**
 * Prepares the {@link MediaPeriod} and asserts that it provides the specified track groups.
 *
 * @param mediaPeriod The {@link MediaPeriod} to test.
 * @param expectedGroups The expected track groups.
 */
public static void assertTrackGroups(MediaPeriod mediaPeriod, TrackGroupArray expectedGroups) {
    TrackGroupArray actualGroups = prepareAndGetTrackGroups(mediaPeriod);
    assertThat(actualGroups).isEqualTo(expectedGroups);
}
Also used : TrackGroupArray(androidx.media3.common.TrackGroupArray)

Example 25 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class ExoPlayerTest method seekDiscontinuityWithAdjustment.

@Test
public void seekDiscontinuityWithAdjustment() throws Exception {
    FakeTimeline timeline = new FakeTimeline(1);
    FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            false);
            mediaPeriod.setSeekToUsOffset(10);
            return mediaPeriod;
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).seek(10).play().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT);
}
Also used : TransferListener(androidx.media3.datasource.TransferListener) Allocator(androidx.media3.exoplayer.upstream.Allocator) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) TrackGroupArray(androidx.media3.common.TrackGroupArray) FakeMediaPeriod(androidx.media3.test.utils.FakeMediaPeriod) FakeTimeline(androidx.media3.test.utils.FakeTimeline) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)117 Test (org.junit.Test)92 Format (androidx.media3.common.Format)60 TrackGroup (androidx.media3.common.TrackGroup)40 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)36 Nullable (androidx.annotation.Nullable)18 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)17 FakeTimeline (androidx.media3.test.utils.FakeTimeline)17 TransferListener (androidx.media3.datasource.TransferListener)14 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)13 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)13 FakeMediaPeriod (androidx.media3.test.utils.FakeMediaPeriod)13 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)13 Allocator (androidx.media3.exoplayer.upstream.Allocator)12 MediaSource (androidx.media3.exoplayer.source.MediaSource)10 MediaItem (androidx.media3.common.MediaItem)9 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)9 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)9 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)9 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)9