Add support for non-Extractor content MediaSources in IMA demo
Issue: #3676 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=181140929
This commit is contained in:
parent
d533a83ae4
commit
67d4626701
@ -43,6 +43,8 @@
|
|||||||
([#2147](https://github.com/google/ExoPlayer/issues/2147)).
|
([#2147](https://github.com/google/ExoPlayer/issues/2147)).
|
||||||
* CacheDataSource: Check periodically if it's possible to read from/write to
|
* CacheDataSource: Check periodically if it's possible to read from/write to
|
||||||
cache after deciding to bypass cache.
|
cache after deciding to bypass cache.
|
||||||
|
* IMA extension: Add support for playing non-Extractor content MediaSources in
|
||||||
|
the IMA demo app ([#3676](https://github.com/google/ExoPlayer/issues/3676)).
|
||||||
|
|
||||||
### 2.6.1 ###
|
### 2.6.1 ###
|
||||||
|
|
||||||
|
@ -45,5 +45,6 @@ dependencies {
|
|||||||
compile project(modulePrefix + 'library-ui')
|
compile project(modulePrefix + 'library-ui')
|
||||||
compile project(modulePrefix + 'library-dash')
|
compile project(modulePrefix + 'library-dash')
|
||||||
compile project(modulePrefix + 'library-hls')
|
compile project(modulePrefix + 'library-hls')
|
||||||
|
compile project(modulePrefix + 'library-smoothstreaming')
|
||||||
compile project(modulePrefix + 'extension-ima')
|
compile project(modulePrefix + 'extension-ima')
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
|||||||
import com.google.android.exoplayer2.source.dash.DashMediaSource;
|
import com.google.android.exoplayer2.source.dash.DashMediaSource;
|
||||||
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
|
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
|
||||||
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
|
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
|
||||||
|
import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource;
|
||||||
|
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
|
||||||
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
||||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||||
@ -79,15 +81,10 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
// Bind the player to the view.
|
// Bind the player to the view.
|
||||||
simpleExoPlayerView.setPlayer(player);
|
simpleExoPlayerView.setPlayer(player);
|
||||||
|
|
||||||
// Produces DataSource instances through which media data is loaded.
|
|
||||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
|
|
||||||
Util.getUserAgent(context, context.getString(R.string.application_name)));
|
|
||||||
|
|
||||||
// This is the MediaSource representing the content media (i.e. not the ad).
|
// This is the MediaSource representing the content media (i.e. not the ad).
|
||||||
String contentUrl = context.getString(R.string.content_url);
|
String contentUrl = context.getString(R.string.content_url);
|
||||||
MediaSource contentMediaSource =
|
MediaSource contentMediaSource =
|
||||||
new ExtractorMediaSource.Factory(dataSourceFactory)
|
buildMediaSource(Uri.parse(contentUrl), /* handler= */ null, /* listener= */ null);
|
||||||
.createMediaSource(Uri.parse(contentUrl));
|
|
||||||
|
|
||||||
// Compose the content media source into a new AdsMediaSource with both ads and content.
|
// Compose the content media source into a new AdsMediaSource with both ads and content.
|
||||||
MediaSource mediaSourceWithAds =
|
MediaSource mediaSourceWithAds =
|
||||||
@ -126,6 +123,19 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
@Override
|
@Override
|
||||||
public MediaSource createMediaSource(
|
public MediaSource createMediaSource(
|
||||||
Uri uri, @Nullable Handler handler, @Nullable MediaSourceEventListener listener) {
|
Uri uri, @Nullable Handler handler, @Nullable MediaSourceEventListener listener) {
|
||||||
|
return buildMediaSource(uri, handler, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getSupportedTypes() {
|
||||||
|
// IMA does not support Smooth Streaming ads.
|
||||||
|
return new int[] {C.TYPE_DASH, C.TYPE_HLS, C.TYPE_OTHER};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal methods.
|
||||||
|
|
||||||
|
private MediaSource buildMediaSource(
|
||||||
|
Uri uri, @Nullable Handler handler, @Nullable MediaSourceEventListener listener) {
|
||||||
@ContentType int type = Util.inferContentType(uri);
|
@ContentType int type = Util.inferContentType(uri);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case C.TYPE_DASH:
|
case C.TYPE_DASH:
|
||||||
@ -133,20 +143,19 @@ import com.google.android.exoplayer2.util.Util;
|
|||||||
new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
|
new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
|
||||||
manifestDataSourceFactory)
|
manifestDataSourceFactory)
|
||||||
.createMediaSource(uri, handler, listener);
|
.createMediaSource(uri, handler, listener);
|
||||||
|
case C.TYPE_SS:
|
||||||
|
return new SsMediaSource.Factory(
|
||||||
|
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), manifestDataSourceFactory)
|
||||||
|
.createMediaSource(uri, handler, listener);
|
||||||
case C.TYPE_HLS:
|
case C.TYPE_HLS:
|
||||||
return new HlsMediaSource.Factory(mediaDataSourceFactory)
|
return new HlsMediaSource.Factory(mediaDataSourceFactory)
|
||||||
.createMediaSource(uri, handler, listener);
|
.createMediaSource(uri, handler, listener);
|
||||||
case C.TYPE_OTHER:
|
case C.TYPE_OTHER:
|
||||||
return new ExtractorMediaSource.Factory(mediaDataSourceFactory)
|
return new ExtractorMediaSource.Factory(mediaDataSourceFactory)
|
||||||
.createMediaSource(uri, handler, listener);
|
.createMediaSource(uri, handler, listener);
|
||||||
case C.TYPE_SS:
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unsupported type: " + type);
|
throw new IllegalStateException("Unsupported type: " + type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] getSupportedTypes() {
|
|
||||||
return new int[] {C.TYPE_DASH, C.TYPE_HLS, C.TYPE_OTHER};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user