Search in sources :

Example 11 with LiveConfiguration

use of com.google.android.exoplayer2.MediaItem.LiveConfiguration in project ExoPlayer by google.

the class DashMediaSourceTest method prepare_withoutLiveConfiguration_withoutMediaItemLiveConfiguration_usesUnitSpeed.

@Test
public void prepare_withoutLiveConfiguration_withoutMediaItemLiveConfiguration_usesUnitSpeed() throws InterruptedException {
    DashMediaSource mediaSource = new DashMediaSource.Factory(() -> createSampleMpdDataSource(SAMPLE_MPD_LIVE_WITHOUT_LIVE_CONFIGURATION)).createMediaSource(MediaItem.fromUri(Uri.EMPTY));
    MediaItem.LiveConfiguration liveConfiguration = prepareAndWaitForTimelineRefresh(mediaSource).liveConfiguration;
    assertThat(liveConfiguration.targetOffsetMs).isEqualTo(DashMediaSource.DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS);
    assertThat(liveConfiguration.minOffsetMs).isEqualTo(0L);
    assertThat(liveConfiguration.maxOffsetMs).isEqualTo(58_000L);
    assertThat(liveConfiguration.minPlaybackSpeed).isEqualTo(1f);
    assertThat(liveConfiguration.maxPlaybackSpeed).isEqualTo(1f);
}
Also used : LiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 12 with LiveConfiguration

use of com.google.android.exoplayer2.MediaItem.LiveConfiguration in project ExoPlayer by google.

the class DefaultMediaSourceFactory method createMediaSource.

@Override
public MediaSource createMediaSource(MediaItem mediaItem) {
    Assertions.checkNotNull(mediaItem.localConfiguration);
    @Nullable String scheme = mediaItem.localConfiguration.uri.getScheme();
    if (scheme != null && scheme.equals(C.SSAI_SCHEME)) {
        return checkNotNull(serverSideAdInsertionMediaSourceFactory).createMediaSource(mediaItem);
    }
    @C.ContentType int type = Util.inferContentTypeForUriAndMimeType(mediaItem.localConfiguration.uri, mediaItem.localConfiguration.mimeType);
    @Nullable MediaSource.Factory mediaSourceFactory = delegateFactoryLoader.getMediaSourceFactory(type);
    checkStateNotNull(mediaSourceFactory, "No suitable media source factory found for content type: " + type);
    MediaItem.LiveConfiguration.Builder liveConfigurationBuilder = mediaItem.liveConfiguration.buildUpon();
    if (mediaItem.liveConfiguration.targetOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setTargetOffsetMs(liveTargetOffsetMs);
    }
    if (mediaItem.liveConfiguration.minPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMinPlaybackSpeed(liveMinSpeed);
    }
    if (mediaItem.liveConfiguration.maxPlaybackSpeed == C.RATE_UNSET) {
        liveConfigurationBuilder.setMaxPlaybackSpeed(liveMaxSpeed);
    }
    if (mediaItem.liveConfiguration.minOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMinOffsetMs(liveMinOffsetMs);
    }
    if (mediaItem.liveConfiguration.maxOffsetMs == C.TIME_UNSET) {
        liveConfigurationBuilder.setMaxOffsetMs(liveMaxOffsetMs);
    }
    MediaItem.LiveConfiguration liveConfiguration = liveConfigurationBuilder.build();
    // Make sure to retain the very same media item instance, if no value needs to be overridden.
    if (!liveConfiguration.equals(mediaItem.liveConfiguration)) {
        mediaItem = mediaItem.buildUpon().setLiveConfiguration(liveConfiguration).build();
    }
    MediaSource mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
    List<MediaItem.SubtitleConfiguration> subtitleConfigurations = castNonNull(mediaItem.localConfiguration).subtitleConfigurations;
    if (!subtitleConfigurations.isEmpty()) {
        MediaSource[] mediaSources = new MediaSource[subtitleConfigurations.size() + 1];
        mediaSources[0] = mediaSource;
        for (int i = 0; i < subtitleConfigurations.size(); i++) {
            if (useProgressiveMediaSourceForSubtitles) {
                Format format = new Format.Builder().setSampleMimeType(subtitleConfigurations.get(i).mimeType).setLanguage(subtitleConfigurations.get(i).language).setSelectionFlags(subtitleConfigurations.get(i).selectionFlags).setRoleFlags(subtitleConfigurations.get(i).roleFlags).setLabel(subtitleConfigurations.get(i).label).setId(subtitleConfigurations.get(i).id).build();
                ExtractorsFactory extractorsFactory = () -> new Extractor[] { SubtitleDecoderFactory.DEFAULT.supportsFormat(format) ? new SubtitleExtractor(SubtitleDecoderFactory.DEFAULT.createDecoder(format), format) : new UnknownSubtitlesExtractor(format) };
                mediaSources[i + 1] = new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(MediaItem.fromUri(subtitleConfigurations.get(i).uri.toString()));
            } else {
                mediaSources[i + 1] = new SingleSampleMediaSource.Factory(dataSourceFactory).setLoadErrorHandlingPolicy(loadErrorHandlingPolicy).createMediaSource(subtitleConfigurations.get(i), /* durationUs= */
                C.TIME_UNSET);
            }
        }
        mediaSource = new MergingMediaSource(mediaSources);
    }
    return maybeWrapWithAdsMediaSource(mediaItem, maybeClipMediaSource(mediaItem, mediaSource));
}
Also used : SubtitleExtractor(com.google.android.exoplayer2.text.SubtitleExtractor) Format(com.google.android.exoplayer2.Format) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) ExtractorsFactory(com.google.android.exoplayer2.extractor.ExtractorsFactory) DefaultExtractorsFactory(com.google.android.exoplayer2.extractor.DefaultExtractorsFactory) MediaItem(com.google.android.exoplayer2.MediaItem) Extractor(com.google.android.exoplayer2.extractor.Extractor) SubtitleExtractor(com.google.android.exoplayer2.text.SubtitleExtractor) Nullable(androidx.annotation.Nullable)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)11 LiveConfiguration (com.google.android.exoplayer2.MediaItem.LiveConfiguration)10 Test (org.junit.Test)10 Nullable (androidx.annotation.Nullable)1 Format (com.google.android.exoplayer2.Format)1 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)1 Extractor (com.google.android.exoplayer2.extractor.Extractor)1 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)1 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)1 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)1 Period (com.google.android.exoplayer2.source.dash.manifest.Period)1 SubtitleExtractor (com.google.android.exoplayer2.text.SubtitleExtractor)1