Use MediaSourceFactory interface to simplify DownloadHelper

PiperOrigin-RevId: 248367983
This commit is contained in:
eguven 2019-05-15 19:13:34 +01:00 committed by Oliver Woodman
parent 8edce41ff3
commit 4ca670bed3
11 changed files with 179 additions and 180 deletions

View file

@ -24,6 +24,7 @@ import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ext.ima.ImaAdsLoader;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
@ -35,7 +36,7 @@ import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
/** Manages the {@link ExoPlayer}, the IMA plugin and all video playback. */
/* package */ final class PlayerManager implements AdsMediaSource.MediaSourceFactory {
/* package */ final class PlayerManager implements MediaSourceFactory {
private final ImaAdsLoader adsLoader;
private final DataSource.Factory dataSourceFactory;
@ -89,7 +90,7 @@ import com.google.android.exoplayer2.util.Util;
adsLoader.release();
}
// AdsMediaSource.MediaSourceFactory implementation.
// MediaSourceFactory implementation.
@Override
public MediaSource createMediaSource(Uri uri) {

View file

@ -50,6 +50,7 @@ import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.source.BehindLiveWindowException;
import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.ads.AdsLoader;
@ -570,8 +571,8 @@ public class PlayerActivity extends AppCompatActivity
adsLoader = loaderConstructor.newInstance(this, adTagUri);
}
adsLoader.setPlayer(player);
AdsMediaSource.MediaSourceFactory adMediaSourceFactory =
new AdsMediaSource.MediaSourceFactory() {
MediaSourceFactory adMediaSourceFactory =
new MediaSourceFactory() {
@Override
public MediaSource createMediaSource(Uri uri) {
return PlayerActivity.this.buildMediaSource(uri);

View file

@ -48,20 +48,14 @@
-dontnote com.google.android.exoplayer2.source.dash.DashMediaSource$Factory
-keepclasseswithmembers class com.google.android.exoplayer2.source.dash.DashMediaSource$Factory {
<init>(com.google.android.exoplayer2.upstream.DataSource$Factory);
** setStreamKeys(java.util.List);
com.google.android.exoplayer2.source.dash.DashMediaSource createMediaSource(android.net.Uri);
}
-dontnote com.google.android.exoplayer2.source.hls.HlsMediaSource$Factory
-keepclasseswithmembers class com.google.android.exoplayer2.source.hls.HlsMediaSource$Factory {
<init>(com.google.android.exoplayer2.upstream.DataSource$Factory);
** setStreamKeys(java.util.List);
com.google.android.exoplayer2.source.hls.HlsMediaSource createMediaSource(android.net.Uri);
}
-dontnote com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource$Factory
-keepclasseswithmembers class com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource$Factory {
<init>(com.google.android.exoplayer2.upstream.DataSource$Factory);
** setStreamKeys(java.util.List);
com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource createMediaSource(android.net.Uri);
}
# Don't warn about checkerframework

View file

@ -31,6 +31,7 @@ import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
@ -51,7 +52,6 @@ import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -107,13 +107,17 @@ public final class DownloadHelper {
void onPrepareError(DownloadHelper helper, IOException e);
}
private static final MediaSourceFactory DASH_FACTORY =
getMediaSourceFactory("com.google.android.exoplayer2.source.dash.DashMediaSource$Factory");
private static final MediaSourceFactory SS_FACTORY =
getMediaSourceFactory(
"com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource$Factory");
private static final MediaSourceFactory HLS_FACTORY =
getMediaSourceFactory("com.google.android.exoplayer2.source.hls.HlsMediaSource$Factory");
@Nullable
private static final Constructor<? extends MediaSourceFactory> DASH_FACTORY_CONSTRUCTOR =
getConstructor("com.google.android.exoplayer2.source.dash.DashMediaSource$Factory");
@Nullable
private static final Constructor<? extends MediaSourceFactory> SS_FACTORY_CONSTRUCTOR =
getConstructor("com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource$Factory");
@Nullable
private static final Constructor<? extends MediaSourceFactory> HLS_FACTORY_CONSTRUCTOR =
getConstructor("com.google.android.exoplayer2.source.hls.HlsMediaSource$Factory");
/**
* Creates a {@link DownloadHelper} for progressive streams.
@ -186,7 +190,8 @@ public final class DownloadHelper {
DownloadRequest.TYPE_DASH,
uri,
/* cacheKey= */ null,
DASH_FACTORY.createMediaSource(uri, dataSourceFactory, /* streamKeys= */ null),
createMediaSourceInternal(
DASH_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
trackSelectorParameters,
Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}
@ -235,7 +240,8 @@ public final class DownloadHelper {
DownloadRequest.TYPE_HLS,
uri,
/* cacheKey= */ null,
HLS_FACTORY.createMediaSource(uri, dataSourceFactory, /* streamKeys= */ null),
createMediaSourceInternal(
HLS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
trackSelectorParameters,
Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}
@ -284,7 +290,8 @@ public final class DownloadHelper {
DownloadRequest.TYPE_SS,
uri,
/* cacheKey= */ null,
SS_FACTORY.createMediaSource(uri, dataSourceFactory, /* streamKeys= */ null),
createMediaSourceInternal(
SS_FACTORY_CONSTRUCTOR, uri, dataSourceFactory, /* streamKeys= */ null),
trackSelectorParameters,
Util.getRendererCapabilities(renderersFactory, drmSessionManager));
}
@ -299,16 +306,16 @@ public final class DownloadHelper {
*/
public static MediaSource createMediaSource(
DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) {
MediaSourceFactory factory;
Constructor<? extends MediaSourceFactory> constructor;
switch (downloadRequest.type) {
case DownloadRequest.TYPE_DASH:
factory = DASH_FACTORY;
constructor = DASH_FACTORY_CONSTRUCTOR;
break;
case DownloadRequest.TYPE_SS:
factory = SS_FACTORY;
constructor = SS_FACTORY_CONSTRUCTOR;
break;
case DownloadRequest.TYPE_HLS:
factory = HLS_FACTORY;
constructor = HLS_FACTORY_CONSTRUCTOR;
break;
case DownloadRequest.TYPE_PROGRESSIVE:
return new ProgressiveMediaSource.Factory(dataSourceFactory)
@ -316,8 +323,8 @@ public final class DownloadHelper {
default:
throw new IllegalStateException("Unsupported type: " + downloadRequest.type);
}
return factory.createMediaSource(
downloadRequest.uri, dataSourceFactory, downloadRequest.streamKeys);
return createMediaSourceInternal(
constructor, downloadRequest.uri, dataSourceFactory, downloadRequest.streamKeys);
}
private final String downloadType;
@ -752,54 +759,39 @@ public final class DownloadHelper {
}
}
private static MediaSourceFactory getMediaSourceFactory(String className) {
Constructor<?> constructor = null;
Method setStreamKeysMethod = null;
Method createMethod = null;
@Nullable
private static Constructor<? extends MediaSourceFactory> getConstructor(String className) {
try {
// LINT.IfChange
Class<?> factoryClazz = Class.forName(className);
constructor = factoryClazz.getConstructor(Factory.class);
setStreamKeysMethod = factoryClazz.getMethod("setStreamKeys", List.class);
createMethod = factoryClazz.getMethod("createMediaSource", Uri.class);
Class<? extends MediaSourceFactory> factoryClazz =
Class.forName(className).asSubclass(MediaSourceFactory.class);
return factoryClazz.getConstructor(Factory.class);
// LINT.ThenChange(../../../../../../../../proguard-rules.txt)
} catch (ClassNotFoundException e) {
// Expected if the app was built without the respective module.
} catch (NoSuchMethodException | SecurityException e) {
return null;
} catch (NoSuchMethodException e) {
// Something is wrong with the library or the proguard configuration.
throw new IllegalStateException(e);
}
return new MediaSourceFactory(constructor, setStreamKeysMethod, createMethod);
}
private static final class MediaSourceFactory {
@Nullable private final Constructor<?> constructor;
@Nullable private final Method setStreamKeysMethod;
@Nullable private final Method createMethod;
public MediaSourceFactory(
@Nullable Constructor<?> constructor,
@Nullable Method setStreamKeysMethod,
@Nullable Method createMethod) {
this.constructor = constructor;
this.setStreamKeysMethod = setStreamKeysMethod;
this.createMethod = createMethod;
private static MediaSource createMediaSourceInternal(
@Nullable Constructor<? extends MediaSourceFactory> constructor,
Uri uri,
Factory dataSourceFactory,
@Nullable List<StreamKey> streamKeys) {
if (constructor == null) {
throw new IllegalStateException("Module missing to create media source.");
}
private MediaSource createMediaSource(
Uri uri, Factory dataSourceFactory, @Nullable List<StreamKey> streamKeys) {
if (constructor == null || setStreamKeysMethod == null || createMethod == null) {
throw new IllegalStateException("Module missing to create media source.");
}
try {
Object factory = constructor.newInstance(dataSourceFactory);
if (streamKeys != null) {
setStreamKeysMethod.invoke(factory, streamKeys);
}
return (MediaSource) Assertions.checkNotNull(createMethod.invoke(factory, uri));
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate media source.", e);
try {
MediaSourceFactory factory = constructor.newInstance(dataSourceFactory);
if (streamKeys != null) {
factory.setStreamKeys(streamKeys);
}
return Assertions.checkNotNull(factory.createMediaSource(uri));
} catch (Exception e) {
throw new IllegalStateException("Failed to instantiate media source.", e);
}
}

View file

@ -24,7 +24,6 @@ import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
@ -61,7 +60,7 @@ public final class ExtractorMediaSource extends BaseMediaSource
/** Use {@link ProgressiveMediaSource.Factory} instead. */
@Deprecated
public static final class Factory implements AdsMediaSource.MediaSourceFactory {
public static final class Factory implements MediaSourceFactory {
private final DataSource.Factory dataSourceFactory;

View file

@ -0,0 +1,51 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.source;
import android.net.Uri;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.offline.StreamKey;
import java.util.List;
/** Factory for creating {@link MediaSource}s from URIs. */
public interface MediaSourceFactory {
/**
* Sets a list of {@link StreamKey StreamKeys} by which the manifest is filtered.
*
* @param streamKeys A list of {@link StreamKey StreamKeys}.
* @return This factory, for convenience.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/
default MediaSourceFactory setStreamKeys(List<StreamKey> streamKeys) {
return this;
}
/**
* Creates a new {@link MediaSource} with the specified {@code uri}.
*
* @param uri The URI to play.
* @return The new {@link MediaSource media source}.
*/
MediaSource createMediaSource(Uri uri);
/**
* Returns the {@link C.ContentType content types} supported by media sources created by this
* factory.
*/
@C.ContentType
int[] getSupportedTypes();
}

View file

@ -21,7 +21,6 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
@ -45,7 +44,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
implements ProgressiveMediaPeriod.Listener {
/** Factory for {@link ProgressiveMediaSource}s. */
public static final class Factory implements AdsMediaSource.MediaSourceFactory {
public static final class Factory implements MediaSourceFactory {
private final DataSource.Factory dataSourceFactory;
@ -87,7 +86,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* possible formats are known, pass a factory that instantiates extractors for those
* formats.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
* @deprecated Pass the {@link ExtractorsFactory} via {@link #Factory(DataSource.Factory,
* ExtractorsFactory)}. This is necessary so that proguard can treat the default extractors
* factory as unused.
@ -106,7 +105,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* @param customCacheKey A custom key that uniquely identifies the original stream. Used for
* cache indexing.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/
public Factory setCustomCacheKey(String customCacheKey) {
Assertions.checkState(!isCreateCalled);
@ -121,7 +120,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
*
* @param tag A tag for the media source.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/
public Factory setTag(Object tag) {
Assertions.checkState(!isCreateCalled);
@ -135,7 +134,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
*
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/
public Factory setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
Assertions.checkState(!isCreateCalled);
@ -152,7 +151,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* each invocation of {@link
* MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/
public Factory setContinueLoadingCheckIntervalBytes(int continueLoadingCheckIntervalBytes) {
Assertions.checkState(!isCreateCalled);

View file

@ -30,6 +30,7 @@ import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.MediaSourceEventListener.LoadEventInfo;
import com.google.android.exoplayer2.source.MediaSourceEventListener.MediaLoadData;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.DataSource;
@ -54,27 +55,6 @@ import java.util.Map;
*/
public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
/** Factory for creating {@link MediaSource}s to play ad media. */
public interface MediaSourceFactory {
/**
* 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.
* @return The new media source.
*/
MediaSource createMediaSource(Uri uri);
/**
* Returns the content types supported by media sources created by this factory. Each element
* should be one of {@link C#TYPE_DASH}, {@link C#TYPE_SS}, {@link C#TYPE_HLS} or {@link
* C#TYPE_OTHER}.
*
* @return The content types supported by media sources created by this factory.
*/
int[] getSupportedTypes();
}
/**
* Wrapper for exceptions that occur while loading ads, which are notified via {@link
* MediaSourceEventListener#onLoadError(int, MediaPeriodId, LoadEventInfo, MediaLoadData,

View file

@ -34,8 +34,8 @@ import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.SequenceableLoader;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.source.dash.PlayerEmsgHandler.PlayerEmsgCallback;
import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
import com.google.android.exoplayer2.source.dash.manifest.DashManifest;
@ -74,7 +74,7 @@ public final class DashMediaSource extends BaseMediaSource {
}
/** Factory for {@link DashMediaSource}s. */
public static final class Factory implements AdsMediaSource.MediaSourceFactory {
public static final class Factory implements MediaSourceFactory {
private final DashChunkSource.Factory chunkSourceFactory;
@Nullable private final DataSource.Factory manifestDataSourceFactory;
@ -213,19 +213,6 @@ public final class DashMediaSource extends BaseMediaSource {
return this;
}
/**
* Sets a list of {@link StreamKey stream keys} by which the manifest is filtered.
*
* @param streamKeys A list of {@link StreamKey stream keys}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
/**
* Sets the factory to create composite {@link SequenceableLoader}s for when this media source
* loads data from multiple streams (video, audio etc...). The default is an instance of {@link
@ -288,6 +275,22 @@ public final class DashMediaSource extends BaseMediaSource {
return mediaSource;
}
/**
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
* MediaSourceEventListener)} instead.
*/
@Deprecated
public DashMediaSource createMediaSource(
Uri manifestUri,
@Nullable Handler eventHandler,
@Nullable MediaSourceEventListener eventListener) {
DashMediaSource mediaSource = createMediaSource(manifestUri);
if (eventHandler != null && eventListener != null) {
mediaSource.addEventListener(eventHandler, eventListener);
}
return mediaSource;
}
/**
* Returns a new {@link DashMediaSource} using the current parameters.
*
@ -316,20 +319,11 @@ public final class DashMediaSource extends BaseMediaSource {
tag);
}
/**
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
* MediaSourceEventListener)} instead.
*/
@Deprecated
public DashMediaSource createMediaSource(
Uri manifestUri,
@Nullable Handler eventHandler,
@Nullable MediaSourceEventListener eventListener) {
DashMediaSource mediaSource = createMediaSource(manifestUri);
if (eventHandler != null && eventListener != null) {
mediaSource.addEventListener(eventHandler, eventListener);
}
return mediaSource;
@Override
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
@Override

View file

@ -29,9 +29,9 @@ import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.SequenceableLoader;
import com.google.android.exoplayer2.source.SinglePeriodTimeline;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistParserFactory;
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistTracker;
import com.google.android.exoplayer2.source.hls.playlist.FilteringHlsPlaylistParserFactory;
@ -56,7 +56,7 @@ public final class HlsMediaSource extends BaseMediaSource
}
/** Factory for {@link HlsMediaSource}s. */
public static final class Factory implements AdsMediaSource.MediaSourceFactory {
public static final class Factory implements MediaSourceFactory {
private final HlsDataSourceFactory hlsDataSourceFactory;
@ -177,19 +177,6 @@ public final class HlsMediaSource extends BaseMediaSource
return this;
}
/**
* Sets a list of {@link StreamKey stream keys} by which the playlists are filtered.
*
* @param streamKeys A list of {@link StreamKey stream keys}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
/**
* Sets the {@link HlsPlaylistTracker} factory. The default value is {@link
* DefaultHlsPlaylistTracker#FACTORY}.
@ -251,6 +238,22 @@ public final class HlsMediaSource extends BaseMediaSource
return this;
}
/**
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
* MediaSourceEventListener)} instead.
*/
@Deprecated
public HlsMediaSource createMediaSource(
Uri playlistUri,
@Nullable Handler eventHandler,
@Nullable MediaSourceEventListener eventListener) {
HlsMediaSource mediaSource = createMediaSource(playlistUri);
if (eventHandler != null && eventListener != null) {
mediaSource.addEventListener(eventHandler, eventListener);
}
return mediaSource;
}
/**
* Returns a new {@link HlsMediaSource} using the current parameters.
*
@ -276,20 +279,11 @@ public final class HlsMediaSource extends BaseMediaSource
tag);
}
/**
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
* MediaSourceEventListener)} instead.
*/
@Deprecated
public HlsMediaSource createMediaSource(
Uri playlistUri,
@Nullable Handler eventHandler,
@Nullable MediaSourceEventListener eventListener) {
HlsMediaSource mediaSource = createMediaSource(playlistUri);
if (eventHandler != null && eventListener != null) {
mediaSource.addEventListener(eventHandler, eventListener);
}
return mediaSource;
@Override
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
@Override

View file

@ -31,9 +31,9 @@ import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.SequenceableLoader;
import com.google.android.exoplayer2.source.SinglePeriodTimeline;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifestParser;
@ -61,7 +61,7 @@ public final class SsMediaSource extends BaseMediaSource
}
/** Factory for {@link SsMediaSource}. */
public static final class Factory implements AdsMediaSource.MediaSourceFactory {
public static final class Factory implements MediaSourceFactory {
private final SsChunkSource.Factory chunkSourceFactory;
@Nullable private final DataSource.Factory manifestDataSourceFactory;
@ -180,19 +180,6 @@ public final class SsMediaSource extends BaseMediaSource
return this;
}
/**
* Sets a list of {@link StreamKey stream keys} by which the manifest is filtered.
*
* @param streamKeys A list of {@link StreamKey stream keys}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
/**
* Sets the factory to create composite {@link SequenceableLoader}s for when this media source
* loads data from multiple streams (video, audio etc.). The default is an instance of {@link
@ -254,6 +241,22 @@ public final class SsMediaSource extends BaseMediaSource
return mediaSource;
}
/**
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
* MediaSourceEventListener)} instead.
*/
@Deprecated
public SsMediaSource createMediaSource(
Uri manifestUri,
@Nullable Handler eventHandler,
@Nullable MediaSourceEventListener eventListener) {
SsMediaSource mediaSource = createMediaSource(manifestUri);
if (eventHandler != null && eventListener != null) {
mediaSource.addEventListener(eventHandler, eventListener);
}
return mediaSource;
}
/**
* Returns a new {@link SsMediaSource} using the current parameters.
*
@ -281,20 +284,11 @@ public final class SsMediaSource extends BaseMediaSource
tag);
}
/**
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
* MediaSourceEventListener)} instead.
*/
@Deprecated
public SsMediaSource createMediaSource(
Uri manifestUri,
@Nullable Handler eventHandler,
@Nullable MediaSourceEventListener eventListener) {
SsMediaSource mediaSource = createMediaSource(manifestUri);
if (eventHandler != null && eventListener != null) {
mediaSource.addEventListener(eventHandler, eventListener);
}
return mediaSource;
@Override
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
@Override