Set player on ads loader in IMA demo

Issue: #5476
PiperOrigin-RevId: 232503736
This commit is contained in:
andrewlewis 2019-02-05 17:46:03 +00:00 committed by Oliver Woodman
parent e3981ec484
commit 589af35c65

View File

@ -29,10 +29,6 @@ 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.hls.HlsMediaSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource; import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
@ -56,14 +52,9 @@ import com.google.android.exoplayer2.util.Util;
} }
public void init(Context context, PlayerView playerView) { public void init(Context context, PlayerView playerView) {
// Create a default track selector.
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
// Create a player instance. // Create a player instance.
player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); player = ExoPlayerFactory.newSimpleInstance(context);
adsLoader.setPlayer(player);
// Bind the player to the view.
playerView.setPlayer(player); playerView.setPlayer(player);
// 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).
@ -89,6 +80,7 @@ import com.google.android.exoplayer2.util.Util;
contentPosition = player.getContentPosition(); contentPosition = player.getContentPosition();
player.release(); player.release();
player = null; player = null;
adsLoader.setPlayer(null);
} }
} }