fix: remove warning and refactor & fix ad workflow (#4235)
This commit is contained in:
parent
f04b233a40
commit
7501880062
@ -2,7 +2,6 @@ package com.brentvatne.common.api
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import com.brentvatne.common.toolbox.DebugLog
|
|
||||||
import com.brentvatne.common.toolbox.ReactBridgeUtils
|
import com.brentvatne.common.toolbox.ReactBridgeUtils
|
||||||
import com.facebook.react.bridge.ReadableMap
|
import com.facebook.react.bridge.ReadableMap
|
||||||
|
|
||||||
@ -26,8 +25,6 @@ class AdsProps {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun parse(src: ReadableMap?): AdsProps {
|
fun parse(src: ReadableMap?): AdsProps {
|
||||||
val adsProps = AdsProps()
|
val adsProps = AdsProps()
|
||||||
DebugLog.w("olivier", "uri: parse AdsProps")
|
|
||||||
|
|
||||||
if (src != null) {
|
if (src != null) {
|
||||||
val uriString = ReactBridgeUtils.safeGetString(src, PROP_AD_TAG_URL)
|
val uriString = ReactBridgeUtils.safeGetString(src, PROP_AD_TAG_URL)
|
||||||
if (TextUtils.isEmpty(uriString)) {
|
if (TextUtils.isEmpty(uriString)) {
|
||||||
|
@ -37,8 +37,8 @@ data class CMCDProps(
|
|||||||
|
|
||||||
return (0 until array.size()).mapNotNull { i ->
|
return (0 until array.size()).mapNotNull { i ->
|
||||||
val item = array.getMap(i)
|
val item = array.getMap(i)
|
||||||
val key = item?.getString("key")
|
val key = item.getString("key")
|
||||||
val value = when (item?.getType("value")) {
|
val value = when (item.getType("value")) {
|
||||||
ReadableType.Number -> item.getDouble("value")
|
ReadableType.Number -> item.getDouble("value")
|
||||||
ReadableType.String -> item.getString("value")
|
ReadableType.String -> item.getString("value")
|
||||||
else -> null
|
else -> null
|
||||||
|
@ -40,7 +40,7 @@ class ExoPlayerView(private val context: Context) :
|
|||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT
|
ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
)
|
)
|
||||||
private var adOverlayFrameLayout: FrameLayout
|
private var adOverlayFrameLayout: FrameLayout? = null
|
||||||
val isPlaying: Boolean
|
val isPlaying: Boolean
|
||||||
get() = player != null && player?.isPlaying == true
|
get() = player != null && player?.isPlaying == true
|
||||||
|
|
||||||
@ -72,12 +72,9 @@ class ExoPlayerView(private val context: Context) :
|
|||||||
|
|
||||||
updateSurfaceView(viewType)
|
updateSurfaceView(viewType)
|
||||||
|
|
||||||
adOverlayFrameLayout = FrameLayout(context)
|
|
||||||
|
|
||||||
layout.addView(shutterView, 1, layoutParams)
|
layout.addView(shutterView, 1, layoutParams)
|
||||||
if (localStyle.subtitlesFollowVideo) {
|
if (localStyle.subtitlesFollowVideo) {
|
||||||
layout.addView(subtitleLayout, layoutParams)
|
layout.addView(subtitleLayout, layoutParams)
|
||||||
layout.addView(adOverlayFrameLayout, layoutParams)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addViewInLayout(layout, 0, aspectRatioParams)
|
addViewInLayout(layout, 0, aspectRatioParams)
|
||||||
@ -194,22 +191,21 @@ class ExoPlayerView(private val context: Context) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideShutterView() {
|
var adsShown = false
|
||||||
shutterView.setVisibility(INVISIBLE)
|
|
||||||
surfaceView?.setAlpha(1f)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showShutterView() {
|
|
||||||
shutterView.setVisibility(VISIBLE)
|
|
||||||
surfaceView?.setAlpha(0f)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showAds() {
|
fun showAds() {
|
||||||
adOverlayFrameLayout.setVisibility(View.VISIBLE)
|
if (!adsShown) {
|
||||||
|
adOverlayFrameLayout = FrameLayout(context)
|
||||||
|
layout.addView(adOverlayFrameLayout, layoutParams)
|
||||||
|
adsShown = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hideAds() {
|
fun hideAds() {
|
||||||
adOverlayFrameLayout.setVisibility(View.GONE)
|
if (adsShown) {
|
||||||
|
layout.removeView(adOverlayFrameLayout)
|
||||||
|
adOverlayFrameLayout = null
|
||||||
|
adsShown = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateShutterViewVisibility() {
|
fun updateShutterViewVisibility() {
|
||||||
|
@ -83,7 +83,6 @@ import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
|
|||||||
import androidx.media3.exoplayer.source.MediaSource;
|
import androidx.media3.exoplayer.source.MediaSource;
|
||||||
import androidx.media3.exoplayer.source.MergingMediaSource;
|
import androidx.media3.exoplayer.source.MergingMediaSource;
|
||||||
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
|
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
|
||||||
import androidx.media3.exoplayer.source.SingleSampleMediaSource;
|
|
||||||
import androidx.media3.exoplayer.source.TrackGroupArray;
|
import androidx.media3.exoplayer.source.TrackGroupArray;
|
||||||
import androidx.media3.exoplayer.source.ads.AdsMediaSource;
|
import androidx.media3.exoplayer.source.ads.AdsMediaSource;
|
||||||
import androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection;
|
import androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection;
|
||||||
@ -827,23 +826,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
mediaSourceFactory.setDataSourceFactory(RNVSimpleCache.INSTANCE.getCacheFactory(buildHttpDataSourceFactory(true)));
|
mediaSourceFactory.setDataSourceFactory(RNVSimpleCache.INSTANCE.getCacheFactory(buildHttpDataSourceFactory(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BuildConfig.USE_EXOPLAYER_IMA) {
|
|
||||||
AdsProps adProps = source.getAdsProps();
|
|
||||||
|
|
||||||
// Create an AdsLoader.
|
|
||||||
ImaAdsLoader.Builder imaLoaderBuilder = new ImaAdsLoader
|
|
||||||
.Builder(themedReactContext)
|
|
||||||
.setAdEventListener(this)
|
|
||||||
.setAdErrorListener(this);
|
|
||||||
|
|
||||||
if (adProps != null && adProps.getAdLanguage() != null) {
|
|
||||||
ImaSdkSettings imaSdkSettings = ImaSdkFactory.getInstance().createImaSdkSettings();
|
|
||||||
imaSdkSettings.setLanguage(adProps.getAdLanguage());
|
|
||||||
imaLoaderBuilder.setImaSdkSettings(imaSdkSettings);
|
|
||||||
}
|
|
||||||
adsLoader = imaLoaderBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaSourceFactory.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
mediaSourceFactory.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
||||||
|
|
||||||
player = new ExoPlayer.Builder(getContext(), renderersFactory)
|
player = new ExoPlayer.Builder(getContext(), renderersFactory)
|
||||||
@ -858,9 +840,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
player.setVolume(muted ? 0.f : audioVolume * 1);
|
player.setVolume(muted ? 0.f : audioVolume * 1);
|
||||||
exoPlayerView.setPlayer(player);
|
exoPlayerView.setPlayer(player);
|
||||||
|
|
||||||
if (adsLoader != null) {
|
|
||||||
adsLoader.setPlayer(player);
|
|
||||||
}
|
|
||||||
audioBecomingNoisyReceiver.setListener(self);
|
audioBecomingNoisyReceiver.setListener(self);
|
||||||
bandwidthMeter.addEventListener(new Handler(), self);
|
bandwidthMeter.addEventListener(new Handler(), self);
|
||||||
setPlayWhenReady(!isPaused);
|
setPlayWhenReady(!isPaused);
|
||||||
@ -875,6 +854,41 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AdsMediaSource initializeAds(MediaSource videoSource, Source runningSource) {
|
||||||
|
AdsProps adProps = runningSource.getAdsProps();
|
||||||
|
Uri uri = runningSource.getUri();
|
||||||
|
if (adProps != null && uri != null) {
|
||||||
|
Uri adTagUrl = adProps.getAdTagUrl();
|
||||||
|
if (adTagUrl != null) {
|
||||||
|
exoPlayerView.showAds();
|
||||||
|
// Create an AdsLoader.
|
||||||
|
ImaAdsLoader.Builder imaLoaderBuilder = new ImaAdsLoader
|
||||||
|
.Builder(themedReactContext)
|
||||||
|
.setAdEventListener(this)
|
||||||
|
.setAdErrorListener(this);
|
||||||
|
|
||||||
|
if (adProps.getAdLanguage() != null) {
|
||||||
|
ImaSdkSettings imaSdkSettings = ImaSdkFactory.getInstance().createImaSdkSettings();
|
||||||
|
imaSdkSettings.setLanguage(adProps.getAdLanguage());
|
||||||
|
imaLoaderBuilder.setImaSdkSettings(imaSdkSettings);
|
||||||
|
}
|
||||||
|
adsLoader = imaLoaderBuilder.build();
|
||||||
|
adsLoader.setPlayer(player);
|
||||||
|
if (adsLoader != null) {
|
||||||
|
DefaultMediaSourceFactory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
||||||
|
.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
||||||
|
DataSpec adTagDataSpec = new DataSpec(adTagUrl);
|
||||||
|
return new AdsMediaSource(videoSource,
|
||||||
|
adTagDataSpec,
|
||||||
|
ImmutableList.of(uri, adTagUrl),
|
||||||
|
mediaSourceFactory, adsLoader, exoPlayerView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exoPlayerView.hideAds();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private DrmSessionManager initializePlayerDrm() {
|
private DrmSessionManager initializePlayerDrm() {
|
||||||
DrmSessionManager drmSessionManager = null;
|
DrmSessionManager drmSessionManager = null;
|
||||||
DRMProps drmProps = source.getDrmProps();
|
DRMProps drmProps = source.getDrmProps();
|
||||||
@ -908,32 +922,17 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// init source to manage ads and external text tracks
|
// init source to manage ads and external text tracks
|
||||||
MediaSource subtitlesSource = buildTextSource();
|
MediaSource videoSource = buildMediaSource(runningSource.getUri(),
|
||||||
MediaSource videoSource = buildMediaSource(runningSource.getUri(), runningSource.getExtension(), drmSessionManager, runningSource.getCropStartMs(), runningSource.getCropEndMs());
|
runningSource.getExtension(),
|
||||||
MediaSource mediaSourceWithAds = null;
|
drmSessionManager,
|
||||||
Uri adTagUrl = null;
|
runningSource.getCropStartMs(),
|
||||||
if (source.getAdsProps() != null) {
|
runningSource.getCropEndMs());
|
||||||
adTagUrl = source.getAdsProps().getAdTagUrl();
|
MediaSource mediaSourceWithAds = initializeAds(videoSource, runningSource);
|
||||||
}
|
MediaSource mediaSource = Objects.requireNonNullElse(mediaSourceWithAds, videoSource);
|
||||||
if (adTagUrl != null && adsLoader != null) {
|
|
||||||
DefaultMediaSourceFactory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
|
||||||
.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
|
||||||
DataSpec adTagDataSpec = new DataSpec(adTagUrl);
|
|
||||||
DebugLog.w(TAG, "ads " + adTagUrl);
|
|
||||||
mediaSourceWithAds = new AdsMediaSource(videoSource, adTagDataSpec, ImmutableList.of(runningSource.getUri(), adTagUrl), mediaSourceFactory, adsLoader, exoPlayerView);
|
|
||||||
exoPlayerView.showAds();
|
|
||||||
}
|
|
||||||
MediaSource mediaSource;
|
|
||||||
if (subtitlesSource == null) {
|
|
||||||
mediaSource = Objects.requireNonNullElse(mediaSourceWithAds, videoSource);
|
|
||||||
} else {
|
|
||||||
ArrayList<MediaSource> mediaSourceList = new ArrayList<>();
|
|
||||||
mediaSourceList.add(subtitlesSource);
|
|
||||||
mediaSourceList.add(0, Objects.requireNonNullElse(mediaSourceWithAds, videoSource));
|
|
||||||
MediaSource[] mediaSourceArray = mediaSourceList.toArray(
|
|
||||||
new MediaSource[mediaSourceList.size()]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
MediaSource subtitlesSource = buildTextSource();
|
||||||
|
if (subtitlesSource != null) {
|
||||||
|
MediaSource[] mediaSourceArray = {mediaSource, subtitlesSource};
|
||||||
mediaSource = new MergingMediaSource(mediaSourceArray);
|
mediaSource = new MergingMediaSource(mediaSourceArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1132,6 +1131,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
drmProvider = new DefaultDrmSessionManagerProvider();
|
drmProvider = new DefaultDrmSessionManagerProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CONTENT_TYPE_SS:
|
case CONTENT_TYPE_SS:
|
||||||
if(!BuildConfig.USE_EXOPLAYER_SMOOTH_STREAMING) {
|
if(!BuildConfig.USE_EXOPLAYER_SMOOTH_STREAMING) {
|
||||||
@ -1905,7 +1905,8 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isSourceEqual) {
|
if (!isSourceEqual) {
|
||||||
reloadSource();
|
playerNeedsSource = true;
|
||||||
|
initializePlayer();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
clearSrc();
|
clearSrc();
|
||||||
@ -1932,11 +1933,6 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
mReportBandwidth = reportBandwidth;
|
mReportBandwidth = reportBandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadSource() {
|
|
||||||
playerNeedsSource = true;
|
|
||||||
initializePlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResizeModeModifier(@ResizeMode.Mode int resizeMode) {
|
public void setResizeModeModifier(@ResizeMode.Mode int resizeMode) {
|
||||||
if (exoPlayerView != null) {
|
if (exoPlayerView != null) {
|
||||||
exoPlayerView.setResizeMode(resizeMode);
|
exoPlayerView.setResizeMode(resizeMode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user