[ADS] Make ImaAdsLoader nullable
This commit is contained in:
parent
8ee6ad9900
commit
8040ac99ce
@ -151,7 +151,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
private ExoPlayerView exoPlayerView;
|
private ExoPlayerView exoPlayerView;
|
||||||
private FullScreenPlayerView fullScreenPlayerView;
|
private FullScreenPlayerView fullScreenPlayerView;
|
||||||
private final ImaAdsLoader adsLoader;
|
private ImaAdsLoader adsLoader;
|
||||||
|
|
||||||
private DataSource.Factory mediaDataSourceFactory;
|
private DataSource.Factory mediaDataSourceFactory;
|
||||||
private ExoPlayer player;
|
private ExoPlayer player;
|
||||||
@ -230,7 +230,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case SHOW_PROGRESS:
|
case SHOW_PROGRESS:
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (isPlayingAd()) {
|
if (playerControlView != null && isPlayingAd() && controls) {
|
||||||
playerControlView.hide();
|
playerControlView.hide();
|
||||||
}
|
}
|
||||||
long pos = player.getCurrentPosition();
|
long pos = player.getCurrentPosition();
|
||||||
@ -273,12 +273,10 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
themedReactContext.addLifecycleEventListener(this);
|
themedReactContext.addLifecycleEventListener(this);
|
||||||
audioBecomingNoisyReceiver = new AudioBecomingNoisyReceiver(themedReactContext);
|
audioBecomingNoisyReceiver = new AudioBecomingNoisyReceiver(themedReactContext);
|
||||||
// Create an AdsLoader.
|
|
||||||
adsLoader = new ImaAdsLoader.Builder(themedReactContext).setAdEventListener(this).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPlayingAd() {
|
private boolean isPlayingAd() {
|
||||||
return player != null && player.isPlayingAd() && player.getPlayWhenReady();
|
return player != null && player.isPlayingAd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -618,6 +616,9 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
new DefaultRenderersFactory(getContext())
|
new DefaultRenderersFactory(getContext())
|
||||||
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
|
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
|
||||||
|
|
||||||
|
// Create an AdsLoader.
|
||||||
|
adsLoader = new ImaAdsLoader.Builder(themedReactContext).setAdEventListener(this).build();
|
||||||
|
|
||||||
MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
||||||
.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
||||||
|
|
||||||
@ -767,10 +768,16 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
: uri.getLastPathSegment());
|
: uri.getLastPathSegment());
|
||||||
config.setDisableDisconnectError(this.disableDisconnectError);
|
config.setDisableDisconnectError(this.disableDisconnectError);
|
||||||
|
|
||||||
MediaItem mediaItem = new MediaItem.Builder()
|
MediaItem.Builder mediaItemBuilder = new MediaItem.Builder().setUri(uri);
|
||||||
.setUri(uri)
|
|
||||||
.setAdsConfiguration(new MediaItem.AdsConfiguration.Builder(adTagUrl).build())
|
if (adTagUrl != null) {
|
||||||
.build();
|
mediaItemBuilder.setAdsConfiguration(
|
||||||
|
new MediaItem.AdsConfiguration.Builder(adTagUrl).build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaItem mediaItem = mediaItemBuilder.build();
|
||||||
|
|
||||||
DrmSessionManagerProvider drmProvider = null;
|
DrmSessionManagerProvider drmProvider = null;
|
||||||
if (drmSessionManager != null) {
|
if (drmSessionManager != null) {
|
||||||
drmProvider = new DrmSessionManagerProvider() {
|
drmProvider = new DrmSessionManagerProvider() {
|
||||||
@ -862,6 +869,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
player = null;
|
player = null;
|
||||||
}
|
}
|
||||||
adsLoader.release();
|
adsLoader.release();
|
||||||
|
adsLoader = null;
|
||||||
progressHandler.removeMessages(SHOW_PROGRESS);
|
progressHandler.removeMessages(SHOW_PROGRESS);
|
||||||
themedReactContext.removeLifecycleEventListener(this);
|
themedReactContext.removeLifecycleEventListener(this);
|
||||||
audioBecomingNoisyReceiver.removeListener();
|
audioBecomingNoisyReceiver.removeListener();
|
||||||
|
Loading…
Reference in New Issue
Block a user