@Override public MediaSource createMediaSource( Uri uri, @Nullable Handler handler, @Nullable MediaSourceEventListener listener) { @ContentType int type = Util.inferContentType(uri); switch (type) { case C.TYPE_DASH: return new DashMediaSource.Factory( new DefaultDashChunkSource.Factory(mediaDataSourceFactory), manifestDataSourceFactory) .createMediaSource(uri, handler, listener); case C.TYPE_HLS: return new HlsMediaSource.Factory(mediaDataSourceFactory) .createMediaSource(uri, handler, listener); case C.TYPE_OTHER: return new ExtractorMediaSource.Factory(mediaDataSourceFactory) .createMediaSource(uri, handler, listener); case C.TYPE_SS: default: throw new IllegalStateException("Unsupported type: " + type); } }
/** * Returns a new {@link HlsMediaSource} using the current parameters. * * @param playlistUri The playlist {@link Uri}. * @param eventHandler A handler for events. * @param eventListener A listener of events. * @return The new {@link HlsMediaSource}. */ @Override public HlsMediaSource createMediaSource( Uri playlistUri, @Nullable Handler eventHandler, @Nullable MediaSourceEventListener eventListener) { isCreateCalled = true; if (playlistParser == null) { playlistParser = new HlsPlaylistParser(); } return new HlsMediaSource( playlistUri, hlsDataSourceFactory, extractorFactory, minLoadableRetryCount, eventHandler, eventListener, playlistParser); }
/** * Returns a new {@link DashMediaSource} using the current parameters and the specified * sideloaded manifest. * * @param manifest The manifest. {@link DashManifest#dynamic} must be false. * @param eventHandler A handler for events. * @param eventListener A listener of events. * @return The new {@link DashMediaSource}. * @throws IllegalArgumentException If {@link DashManifest#dynamic} is true. */ public DashMediaSource createMediaSource( DashManifest manifest, @Nullable Handler eventHandler, @Nullable MediaSourceEventListener eventListener) { Assertions.checkArgument(!manifest.dynamic); isCreateCalled = true; return new DashMediaSource( manifest, null, null, null, chunkSourceFactory, minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener); }
/** * Returns a new {@link SsMediaSource} using the current parameters and the specified sideloaded * manifest. * * @param manifest The manifest. {@link SsManifest#isLive} must be false. * @param eventHandler A handler for events. * @param eventListener A listener of events. * @return The new {@link SsMediaSource}. * @throws IllegalArgumentException If {@link SsManifest#isLive} is true. */ public SsMediaSource createMediaSource( SsManifest manifest, @Nullable Handler eventHandler, @Nullable MediaSourceEventListener eventListener) { Assertions.checkArgument(!manifest.isLive); isCreateCalled = true; return new SsMediaSource( manifest, null, null, null, chunkSourceFactory, minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener); }
private SsMediaSource(SsManifest manifest, Uri manifestUri, DataSource.Factory manifestDataSourceFactory, ParsingLoadable.Parser<? extends SsManifest> manifestParser, SsChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, long livePresentationDelayMs, Handler eventHandler, MediaSourceEventListener eventListener) { Assertions.checkState(manifest == null || !manifest.isLive); this.manifest = manifest; this.manifestUri = manifestUri == null ? null : Util.toLowerInvariant(manifestUri.getLastPathSegment()).matches("manifest(\\(.+\\))?") ? manifestUri : Uri.withAppendedPath(manifestUri, "Manifest"); this.manifestDataSourceFactory = manifestDataSourceFactory; this.manifestParser = manifestParser; this.chunkSourceFactory = chunkSourceFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.livePresentationDelayMs = livePresentationDelayMs; this.eventDispatcher = new EventDispatcher(eventHandler, eventListener); mediaPeriods = new ArrayList<>(); }
private MediaSource buildMediaSource( Uri uri, String overrideExtension, @Nullable Handler handler, @Nullable MediaSourceEventListener listener) { @ContentType int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension); switch (type) { case C.TYPE_DASH: return new DashMediaSource.Factory( new DefaultDashChunkSource.Factory(mediaDataSourceFactory), buildDataSourceFactory(false)) .createMediaSource(uri, handler, listener); case C.TYPE_SS: return new SsMediaSource.Factory( new DefaultSsChunkSource.Factory(mediaDataSourceFactory), buildDataSourceFactory(false)) .createMediaSource(uri, handler, listener); case C.TYPE_HLS: return new HlsMediaSource.Factory(mediaDataSourceFactory) .createMediaSource(uri, handler, listener); case C.TYPE_OTHER: return new ExtractorMediaSource.Factory(mediaDataSourceFactory) .createMediaSource(uri, handler, listener); default: { throw new IllegalStateException("Unsupported type: " + type); } } }
/** * Returns an ads media source, reusing the ads loader if one exists. * * @throws Exception Thrown if it was not possible to create an ads media source, for example, due * to a missing dependency. */ private MediaSource createAdsMediaSource(MediaSource mediaSource, Uri adTagUri) throws Exception { // Load the extension source using reflection so the demo app doesn't have to depend on it. // The ads loader is reused for multiple playbacks, so that ad playback can resume. Class<?> loaderClass = Class.forName("com.google.android.exoplayer2.ext.ima.ImaAdsLoader"); if (adsLoader == null) { adsLoader = (AdsLoader) loaderClass.getConstructor(Context.class, Uri.class) .newInstance(this, adTagUri); adUiViewGroup = new FrameLayout(this); // The demo app has a non-null overlay frame layout. simpleExoPlayerView.getOverlayFrameLayout().addView(adUiViewGroup); } AdsMediaSource.MediaSourceFactory adMediaSourceFactory = new AdsMediaSource.MediaSourceFactory() { @Override public MediaSource createMediaSource( Uri uri, @Nullable Handler handler, @Nullable MediaSourceEventListener listener) { return PlayerActivity.this.buildMediaSource( uri, /* overrideExtension= */ null, handler, listener); } @Override public int[] getSupportedTypes() { return new int[] {C.TYPE_DASH, C.TYPE_SS, C.TYPE_HLS, C.TYPE_OTHER}; } }; return new AdsMediaSource( mediaSource, adMediaSourceFactory, adsLoader, adUiViewGroup, mainHandler, eventLogger); }
public FakeAdaptiveMediaSource( Timeline timeline, Object manifest, TrackGroupArray trackGroupArray, Handler eventHandler, MediaSourceEventListener eventListener, FakeChunkSource.Factory chunkSourceFactory) { super(timeline, manifest, trackGroupArray); this.eventDispatcher = new EventDispatcher(eventHandler, eventListener); this.chunkSourceFactory = chunkSourceFactory; }
private DashMediaSource(DashManifest manifest, Uri manifestUri, DataSource.Factory manifestDataSourceFactory, ParsingLoadable.Parser<? extends DashManifest> manifestParser, DashChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, long livePresentationDelayMs, Handler eventHandler, MediaSourceEventListener eventListener) { this.manifest = manifest; this.manifestUri = manifestUri; this.manifestDataSourceFactory = manifestDataSourceFactory; this.manifestParser = manifestParser; this.chunkSourceFactory = chunkSourceFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.livePresentationDelayMs = livePresentationDelayMs; sideloadedManifest = manifest != null; eventDispatcher = new EventDispatcher(eventHandler, eventListener); manifestUriLock = new Object(); periodsById = new SparseArray<>(); if (sideloadedManifest) { Assertions.checkState(!manifest.dynamic); manifestCallback = null; refreshManifestRunnable = null; simulateManifestRefreshRunnable = null; } else { manifestCallback = new ManifestCallback(); refreshManifestRunnable = new Runnable() { @Override public void run() { startLoadingManifest(); } }; simulateManifestRefreshRunnable = new Runnable() { @Override public void run() { processManifest(false); } }; } }
/** * @param manifestUri The {@link Uri} of the HLS manifest. * @param dataSourceFactory An {@link HlsDataSourceFactory} for {@link DataSource}s for manifests, * segments and keys. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener An {@link MediaSourceEventListener}. May be null if delivery of events is * not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public HlsMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifestUri, dataSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler, eventListener); }
/** * @param manifestUri The {@link Uri} of the HLS manifest. * @param dataSourceFactory An {@link HlsDataSourceFactory} for {@link DataSource}s for manifests, * segments and keys. * @param minLoadableRetryCount The minimum number of times loads must be retried before * errors are propagated. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener An {@link MediaSourceEventListener}. May be null if delivery of events is * not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public HlsMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory, int minLoadableRetryCount, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifestUri, new DefaultHlsDataSourceFactory(dataSourceFactory), HlsExtractorFactory.DEFAULT, minLoadableRetryCount, eventHandler, eventListener, new HlsPlaylistParser()); }
/** * @param manifestUri The {@link Uri} of the HLS manifest. * @param dataSourceFactory An {@link HlsDataSourceFactory} for {@link DataSource}s for manifests, * segments and keys. * @param extractorFactory An {@link HlsExtractorFactory} for {@link Extractor}s for the segments. * @param minLoadableRetryCount The minimum number of times loads must be retried before * errors are propagated. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener An {@link MediaSourceEventListener}. May be null if delivery of events is * not required. * @param playlistParser A {@link ParsingLoadable.Parser} for HLS playlists. * @deprecated Use {@link Factory} instead. */ @Deprecated public HlsMediaSource(Uri manifestUri, HlsDataSourceFactory dataSourceFactory, HlsExtractorFactory extractorFactory, int minLoadableRetryCount, Handler eventHandler, MediaSourceEventListener eventListener, ParsingLoadable.Parser<HlsPlaylist> playlistParser) { this.manifestUri = manifestUri; this.dataSourceFactory = dataSourceFactory; this.extractorFactory = extractorFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.playlistParser = playlistParser; eventDispatcher = new EventDispatcher(eventHandler, eventListener); }
/** * Constructs an instance to play a given {@link DashManifest}, which must be static. * * @param manifest The manifest. {@link DashManifest#dynamic} must be false. * @param chunkSourceFactory A factory for {@link DashChunkSource} instances. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public DashMediaSource(DashManifest manifest, DashChunkSource.Factory chunkSourceFactory, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifest, chunkSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler, eventListener); }
/** * Constructs an instance to play a given {@link DashManifest}, which must be static. * * @param manifest The manifest. {@link DashManifest#dynamic} must be false. * @param chunkSourceFactory A factory for {@link DashChunkSource} instances. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public DashMediaSource(DashManifest manifest, DashChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifest, null, null, null, chunkSourceFactory, minLoadableRetryCount, DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS, eventHandler, eventListener); }
/** * Constructs an instance to play the manifest at a given {@link Uri}, which may be dynamic or * static. * * @param manifestUri The manifest {@link Uri}. * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used * to load (and refresh) the manifest. * @param chunkSourceFactory A factory for {@link DashChunkSource} instances. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public DashMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory, DashChunkSource.Factory chunkSourceFactory, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifestUri, manifestDataSourceFactory, chunkSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS, eventHandler, eventListener); }
/** * Constructs an instance to play the manifest at a given {@link Uri}, which may be dynamic or * static. * * @param manifestUri The manifest {@link Uri}. * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used * to load (and refresh) the manifest. * @param chunkSourceFactory A factory for {@link DashChunkSource} instances. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the * default start position should precede the end of the live window. Use * {@link #DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS} to use the value specified by * the manifest, if present. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public DashMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory, DashChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, long livePresentationDelayMs, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifestUri, manifestDataSourceFactory, new DashManifestParser(), chunkSourceFactory, minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener); }
/** * Constructs an instance to play the manifest at a given {@link Uri}, which may be dynamic or * static. * * @param manifestUri The manifest {@link Uri}. * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used * to load (and refresh) the manifest. * @param manifestParser A parser for loaded manifest data. * @param chunkSourceFactory A factory for {@link DashChunkSource} instances. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the * default start position should precede the end of the live window. Use * {@link #DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS} to use the value specified by * the manifest, if present. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public DashMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory, ParsingLoadable.Parser<? extends DashManifest> manifestParser, DashChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, long livePresentationDelayMs, Handler eventHandler, MediaSourceEventListener eventListener) { this(null, manifestUri, manifestDataSourceFactory, manifestParser, chunkSourceFactory, minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener); }
/** * Constructs an instance to play a given {@link SsManifest}, which must not be live. * * @param manifest The manifest. {@link SsManifest#isLive} must be false. * @param chunkSourceFactory A factory for {@link SsChunkSource} instances. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public SsMediaSource(SsManifest manifest, SsChunkSource.Factory chunkSourceFactory, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifest, chunkSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler, eventListener); }
/** * Constructs an instance to play a given {@link SsManifest}, which must not be live. * * @param manifest The manifest. {@link SsManifest#isLive} must be false. * @param chunkSourceFactory A factory for {@link SsChunkSource} instances. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public SsMediaSource(SsManifest manifest, SsChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifest, null, null, null, chunkSourceFactory, minLoadableRetryCount, DEFAULT_LIVE_PRESENTATION_DELAY_MS, eventHandler, eventListener); }
/** * Constructs an instance to play the manifest at a given {@link Uri}, which may be live or * on-demand. * * @param manifestUri The manifest {@link Uri}. * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used * to load (and refresh) the manifest. * @param chunkSourceFactory A factory for {@link SsChunkSource} instances. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public SsMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory, SsChunkSource.Factory chunkSourceFactory, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifestUri, manifestDataSourceFactory, chunkSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, DEFAULT_LIVE_PRESENTATION_DELAY_MS, eventHandler, eventListener); }
/** * Constructs an instance to play the manifest at a given {@link Uri}, which may be live or * on-demand. * * @param manifestUri The manifest {@link Uri}. * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used * to load (and refresh) the manifest. * @param chunkSourceFactory A factory for {@link SsChunkSource} instances. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the * default start position should precede the end of the live window. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public SsMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory, SsChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, long livePresentationDelayMs, Handler eventHandler, MediaSourceEventListener eventListener) { this(manifestUri, manifestDataSourceFactory, new SsManifestParser(), chunkSourceFactory, minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener); }
/** * Constructs an instance to play the manifest at a given {@link Uri}, which may be live or * on-demand. * * @param manifestUri The manifest {@link Uri}. * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used * to load (and refresh) the manifest. * @param manifestParser A parser for loaded manifest data. * @param chunkSourceFactory A factory for {@link SsChunkSource} instances. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the * default start position should precede the end of the live window. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public SsMediaSource(Uri manifestUri, DataSource.Factory manifestDataSourceFactory, ParsingLoadable.Parser<? extends SsManifest> manifestParser, SsChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount, long livePresentationDelayMs, Handler eventHandler, MediaSourceEventListener eventListener) { this(null, manifestUri, manifestDataSourceFactory, manifestParser, chunkSourceFactory, minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener); }
/** * 用于通知自适应的回调接口获取视频线路名称 * * @param sourceEventListener 实例 */ public void setAdaptiveMediaSourceEventListener(MediaSourceEventListener sourceEventListener) { this.sourceEventListener = sourceEventListener; }
/** * Creates a new {@link MediaSource} for loading the ad media with the specified {@code uri}. * * @param uri The URI of the media or manifest to play. * @param handler A handler for listener events. May be null if delivery of events is not * required. * @param listener A listener for events. May be null if delivery of events is not required. * @return The new media source. */ MediaSource createMediaSource( Uri uri, @Nullable Handler handler, @Nullable MediaSourceEventListener listener);