Skip to content

Commit

Permalink
Updated to ExoPlayer 2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwernick committed May 9, 2018
1 parent 9336f85 commit 5d36323
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ allprojects {
}

ext {
exoPlayerVersion = "2.7.3"
exoPlayerVersion = "2.8.0"
supportLibVersion = "27.1.1"
}
19 changes: 14 additions & 5 deletions demo/src/main/java/com/devbrackets/android/exomediademo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.squareup.leakcanary.LeakCanary;

import java.io.File;

import okhttp3.OkHttpClient;

public class App extends Application {
Expand All @@ -41,15 +43,22 @@ private void configureExoMedia() {
// Registers the media sources to use the OkHttp client instead of the standard Apache one
// Note: the OkHttpDataSourceFactory can be found in the ExoPlayer extension library `extension-okhttp`
ExoMedia.setDataSourceFactoryProvider(new ExoMedia.DataSourceFactoryProvider() {
@Nullable
private CacheDataSourceFactory instance;

@NonNull
@Override
public DataSource.Factory provide(@NonNull String userAgent, @Nullable TransferListener<? super DataSource> listener) {
// Updates the network data source to use the OKHttp implementation
DataSource.Factory upstreamFactory = new OkHttpDataSourceFactory(new OkHttpClient(), userAgent, listener);
if (instance == null) {
// Updates the network data source to use the OKHttp implementation
DataSource.Factory upstreamFactory = new OkHttpDataSourceFactory(new OkHttpClient(), userAgent, listener);

// Adds a cache around the upstreamFactory
Cache cache = new SimpleCache(new File(getCacheDir(), "ExoMediaCache"), new LeastRecentlyUsedCacheEvictor(50 * 1024 * 1024));
instance = new CacheDataSourceFactory(cache, upstreamFactory, CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
}

// Adds a cache around the upstreamFactory
Cache cache = new SimpleCache(getCacheDir(), new LeastRecentlyUsedCacheEvictor(50 * 1024 * 1024));
return new CacheDataSourceFactory(cache, upstreamFactory, CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
return instance;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.FixedTrackSelection;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
Expand Down Expand Up @@ -277,7 +275,7 @@ public Map<RendererType, TrackGroupArray> getAvailableTracks() {
RendererType[] types = new RendererType[] {RendererType.AUDIO, RendererType.VIDEO, RendererType.CLOSED_CAPTION, RendererType.METADATA};
for (RendererType type : types) {
int exoPlayerTrackIndex = getExoPlayerTrackIndex(type);
if (mappedTrackInfo.length > exoPlayerTrackIndex) {
if (mappedTrackInfo.getRendererCount() > exoPlayerTrackIndex) {
trackMap.put(type, mappedTrackInfo.getTrackGroups(exoPlayerTrackIndex));
}
}
Expand All @@ -295,7 +293,7 @@ public int getSelectedTrackIndex(@NonNull RendererType type) {
}

// Verifies the track selection has been overridden
MappingTrackSelector.SelectionOverride selectionOverride = trackSelector.getSelectionOverride(exoPlayerTrackIndex, trackGroupArray);
DefaultTrackSelector.SelectionOverride selectionOverride = trackSelector.getParameters().getSelectionOverride(exoPlayerTrackIndex, trackGroupArray);
if (selectionOverride == null || selectionOverride.groupIndex != exoPlayerTrackIndex || selectionOverride.length <= 0) {
return -1;
}
Expand All @@ -312,18 +310,14 @@ public void setSelectedTrack(@NonNull RendererType type, int index) {
return;
}

// Creates the track selection override
int[] tracks = new int[] {index};
TrackSelection.Factory factory = new FixedTrackSelection.Factory();
MappingTrackSelector.SelectionOverride selectionOverride = new MappingTrackSelector.SelectionOverride(factory, exoPlayerTrackIndex, tracks);

// Specifies the correct track to use
trackSelector.setSelectionOverride(exoPlayerTrackIndex, trackGroupArray, selectionOverride);
DefaultTrackSelector.SelectionOverride selectionOverride = new DefaultTrackSelector.SelectionOverride(exoPlayerTrackIndex, index);
trackSelector.setParameters(trackSelector.buildUponParameters().setSelectionOverride(exoPlayerTrackIndex, trackGroupArray, selectionOverride));
}

public void setRendererEnabled(@NonNull RendererType type, boolean enabled) {
int exoPlayerTrackIndex = getExoPlayerTrackIndex(type);
trackSelector.setRendererDisabled(exoPlayerTrackIndex, !enabled);
trackSelector.setParameters(trackSelector.buildUponParameters().setRendererDisabled(exoPlayerTrackIndex, !enabled));
}

public void setVolume(@FloatRange(from = 0.0, to = 1.0) float volume) {
Expand Down Expand Up @@ -626,7 +620,9 @@ protected DrmSessionManager<FrameworkMediaCrypto> generateDrmSessionManager() {
UUID uuid = C.WIDEVINE_UUID;

try {
return new DefaultDrmSessionManager<>(uuid, FrameworkMediaDrm.newInstance(uuid), new DelegatedMediaDrmCallback(), null, mainHandler, capabilitiesListener);
DefaultDrmSessionManager<FrameworkMediaCrypto> sessionManager = new DefaultDrmSessionManager<>(uuid, FrameworkMediaDrm.newInstance(uuid), new DelegatedMediaDrmCallback(), null);
sessionManager.addListener(mainHandler, capabilitiesListener);
return sessionManager;
} catch (Exception e) {
Log.d(TAG, "Unable to create a DrmSessionManager due to an exception", e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public List<Renderer> generate() {
@NonNull
protected List<Renderer> buildAudioRenderers() {
List<Renderer> renderers = new ArrayList<>();

renderers.add(new MediaCodecAudioRenderer(MediaCodecSelector.DEFAULT, drmSessionManager, true, handler, audioRendererEventListener, AudioCapabilities.getCapabilities(context)));
renderers.add(new MediaCodecAudioRenderer(context, MediaCodecSelector.DEFAULT, drmSessionManager, true, handler, audioRendererEventListener, AudioCapabilities.getCapabilities(context)));

// Adds any registered classes
List<String> classNames = ExoMedia.Data.registeredRendererClasses.get(ExoMedia.RendererType.AUDIO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public MediaSource build(@NonNull Context context, @NonNull Uri uri, @NonNull St
DataSource.Factory meteredDataSourceFactory = buildDataSourceFactory(context, userAgent, transferListener);

return new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(meteredDataSourceFactory), dataSourceFactory)
.createMediaSource(uri, handler, null);
.createMediaSource(uri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public MediaSource build(@NonNull Context context, @NonNull Uri uri, @NonNull St

return new ExtractorMediaSource.Factory(dataSourceFactory)
.setExtractorsFactory(new DefaultExtractorsFactory())
.createMediaSource(uri, handler, null);
.createMediaSource(uri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public MediaSource build(@NonNull Context context, @NonNull Uri uri, @NonNull St
DataSource.Factory dataSourceFactory = buildDataSourceFactory(context, userAgent, transferListener);

return new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri, handler, null);
.createMediaSource(uri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public MediaSource build(@NonNull Context context, @NonNull Uri uri, @NonNull St
DataSource.Factory meteredDataSourceFactory = buildDataSourceFactory(context, userAgent, transferListener);

return new SsMediaSource.Factory(new DefaultSsChunkSource.Factory(meteredDataSourceFactory), dataSourceFactory)
.createMediaSource(uri, handler, null);
.createMediaSource(uri);
}
}

0 comments on commit 5d36323

Please sign in to comment.