From 2a1314e10ae24c9e9194c476cd566ea0c2090a58 Mon Sep 17 00:00:00 2001 From: Guoen Yong Date: Mon, 18 Nov 2024 10:22:40 +0800 Subject: [PATCH] Apply doris-android 4.x (vesper branch) --- .../ReactTVExoDorisExtensionFactory.java | 63 +++++++++++++++++++ .../exoplayer/ReactTVExoDorisFactory.java | 43 +++---------- .../exoplayer/ReactTVExoplayerView.java | 47 +++++++------- .../java/com/dice/messaging/DiceMessageEx.kt | 1 + .../java/com/dice/messaging/DorisPlayerEx.kt | 2 + package.json | 2 +- 6 files changed, 98 insertions(+), 60 deletions(-) create mode 100644 android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisExtensionFactory.java diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisExtensionFactory.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisExtensionFactory.java new file mode 100644 index 0000000000..80295a93d7 --- /dev/null +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisExtensionFactory.java @@ -0,0 +1,63 @@ +package com.brentvatne.exoplayer; + +import static androidx.media3.common.util.Assertions.checkNotNull; + +import androidx.annotation.NonNull; +import androidx.media3.common.AdViewProvider; + +import com.diceplatform.doris.ExoDoris; +import com.diceplatform.doris.common.ad.ui.AdChoicesClickViewRenderer; +import com.diceplatform.doris.entity.DorisAdEvent.AdType; +import com.diceplatform.doris.entity.Source; +import com.diceplatform.doris.ext.imacsai.ExoDorisImaCsaiExtension; +import com.diceplatform.doris.ext.imacsailive.ExoDorisImaCsaiLiveExtension; +import com.diceplatform.doris.ext.imadai.ExoDorisImaDaiExtension; +import com.diceplatform.doris.ext.mediatailor.ssai.ExoDorisAmtSsaiExtension; +import com.diceplatform.doris.ext.yossai.ExoDorisYoSsaiExtension; +import com.diceplatform.doris.extension.ExoDorisExtension; +import com.diceplatform.doris.service.ServiceContainer; + +/** + * A factory class that produces a test playlist data set. + */ +public final class ReactTVExoDorisExtensionFactory implements ExoDorisExtension.Provider { + + private final AdViewProvider adViewProvider; + private final AdChoicesClickViewRenderer adChoicesClickViewRenderer; + + public ReactTVExoDorisExtensionFactory(AdViewProvider adViewProvider, AdChoicesClickViewRenderer adChoicesClickViewRenderer) { + this.adViewProvider = adViewProvider; + this.adChoicesClickViewRenderer = adChoicesClickViewRenderer; + } + + @NonNull + @Override + public ExoDorisExtension createExtension( + @NonNull ExoDoris player, + @NonNull ServiceContainer serviceContainer, + @NonNull Source source) { + AdType adType = Source.getAdType(source); + ExoDorisExtension extension = ExoDoris.DUMMY_PLAYER_EXTENSION; + if (adType == null) { + return extension; + } + switch (adType) { + case YO_SSAI: + extension = new ExoDorisYoSsaiExtension(player, serviceContainer, checkNotNull(adViewProvider), adChoicesClickViewRenderer); + break; + case AMT_SSAI: + extension = new ExoDorisAmtSsaiExtension(player, serviceContainer, checkNotNull(adViewProvider)); + break; + case IMA_DAI: + extension = new ExoDorisImaDaiExtension(player, serviceContainer, checkNotNull(adViewProvider)); + break; + case IMA_CSAI_LIVE: + extension = new ExoDorisImaCsaiLiveExtension(player, serviceContainer, checkNotNull(adViewProvider), null); + break; + case IMA_CSAI: + extension = new ExoDorisImaCsaiExtension(player, serviceContainer, checkNotNull(adViewProvider)); + break; + } + return extension; + } +} diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisFactory.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisFactory.java index cb97536f31..1c0c7d00e0 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisFactory.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoDorisFactory.java @@ -1,7 +1,5 @@ package com.brentvatne.exoplayer; -import static androidx.media3.common.util.Assertions.checkNotNull; - import android.content.Context; import androidx.annotation.NonNull; @@ -11,17 +9,9 @@ import com.diceplatform.doris.ExoDoris; import com.diceplatform.doris.ExoDorisBuilder; -import com.diceplatform.doris.common.ad.AdChoicesTvListener; -import com.diceplatform.doris.common.ad.AdGlobalSettings; +import com.diceplatform.doris.common.ad.ui.AdChoicesClickViewRenderer; import com.diceplatform.doris.entity.DorisAdEvent.AdType; import com.diceplatform.doris.entity.TracksPolicy; -import com.diceplatform.doris.ext.imacsai.ExoDorisImaCsaiBuilder; -import com.diceplatform.doris.ext.imacsailive.ExoDorisImaCsaiLiveBuilder; -import com.diceplatform.doris.ext.imadai.ExoDorisImaDaiBuilder; -import com.diceplatform.doris.ext.yossai.ExoDorisYoSsaiBuilder; -import com.diceplatform.doris.plugin.Plugin; - -import java.util.List; public final class ReactTVExoDorisFactory { @@ -32,8 +22,7 @@ public ExoDoris createPlayer( long forwardIncrementMs, long rewindIncrementMs, @Nullable AdViewProvider adViewProvider, - @Nullable AdChoicesTvListener adChoicesTvListener, - AdGlobalSettings adGlobalSettings, + @Nullable AdChoicesClickViewRenderer adChoicesClickViewRenderer, TracksPolicy tracksPolicy) { return createPlayer( context, @@ -44,10 +33,8 @@ public ExoDoris createPlayer( forwardIncrementMs, rewindIncrementMs, null, - null, adViewProvider, - adChoicesTvListener, - adGlobalSettings, + adChoicesClickViewRenderer, tracksPolicy); } @@ -59,37 +46,21 @@ public ExoDoris createPlayer( int loadBufferMs, long forwardIncrementMs, long rewindIncrementMs, - @Nullable List plugins, @Nullable Parameters.Builder parametersBuilder, @Nullable AdViewProvider adViewProvider, - @Nullable AdChoicesTvListener adChoicesTvListener, - AdGlobalSettings adGlobalSettings, + @Nullable AdChoicesClickViewRenderer adChoicesClickViewRenderer, @Nullable TracksPolicy tracksPolicy) { - final ExoDorisBuilder builder; - if (adType == AdType.YO_SSAI) { - builder = new ExoDorisYoSsaiBuilder(context) - .setAdViewProvider(checkNotNull(adViewProvider)) - .setAdChoicesTvListener(adChoicesTvListener) - .setAdGlobalSettings(adGlobalSettings); - } else if (adType == AdType.IMA_DAI) { - builder = new ExoDorisImaDaiBuilder(context).setAdViewProvider(checkNotNull(adViewProvider)); - } else if (adType == AdType.IMA_CSAI_LIVE) { - builder = new ExoDorisImaCsaiLiveBuilder(context).setAdViewProvider(checkNotNull(adViewProvider)); - } else if (adType == AdType.IMA_CSAI) { - builder = new ExoDorisImaCsaiBuilder(context).setAdViewProvider(checkNotNull(adViewProvider)); - } else { - builder = new ExoDorisBuilder(context); - } - return builder + return new ExoDorisBuilder(context) + .setEnableManifestScte35(adType == AdType.IMA_CSAI_LIVE) .setPlayWhenReady(playWhenReady) .setUserAgent(userAgent) .setLoadBufferMs(loadBufferMs) .setForwardIncrementMs(forwardIncrementMs) .setRewindIncrementMs(rewindIncrementMs) - .setPlugins(plugins) .setParamsBuilder(parametersBuilder) .setTracksPolicy(tracksPolicy) + .setPlayerExtensionProvider(new ReactTVExoDorisExtensionFactory(adViewProvider, adChoicesClickViewRenderer)) .build(); } } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java index be904b8dbe..f932b397fc 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java @@ -83,8 +83,8 @@ import com.diceplatform.doris.entity.Track; import com.diceplatform.doris.entity.TracksPolicy; import com.diceplatform.doris.entity.YoSsaiProperties; -import com.diceplatform.doris.ext.imacsailive.ExoDorisImaCsaiLivePlayer; import com.diceplatform.doris.internal.ResumePositionHandler; +import com.diceplatform.doris.service.LocalizationService; import com.diceplatform.doris.ui.ExoDorisPlayerTvControlView; import com.diceplatform.doris.ui.ExoDorisPlayerView; import com.diceplatform.doris.ui.ExoDorisPlayerViewListener; @@ -94,7 +94,6 @@ import com.diceplatform.doris.ui.entity.VideoTile; import com.diceplatform.doris.ui.skipmarker.SkipMarker; import com.diceplatform.doris.util.DorisExceptionUtil; -import com.diceplatform.doris.util.LocalizationService; import com.diceplatform.doris.util.TrackUtils; import com.facebook.react.ReactApplication; import com.facebook.react.ReactRootView; @@ -177,7 +176,7 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener private ExoDoris player; private ExoDorisTrackSelector trackSelector; private Source source; - private LocalizationService localizationService; + private final LocalizationService localizationService; private boolean playerNeedsSource; private long resumePosition; // unit: millisecond private boolean loadVideoStarted; @@ -353,7 +352,7 @@ public ReactTVExoplayerView(ThemedReactContext context) { mediaSession = new MediaSessionCompat(getContext(), getContext().getPackageName()); mediaSessionConnector = new MediaSessionConnector(mediaSession); - localizationService = new LocalizationService(Locale.getDefault()); + localizationService = new LocalizationService(new LocalizationService.Config()); boolean isRTL = I18nUtil.getInstance().isRTL(getContext()); ExoDorisPlayerTvControlView controller = exoDorisPlayerView.findViewById(R.id.exo_controller); @@ -520,15 +519,6 @@ private void doInitializePlayer(boolean force) { AdViewProvider adViewProvider = adType == AdType.IMA_CSAI_LIVE ? secondaryPlayerView : exoDorisPlayerView; - AdLabels adLabels = translations == null ? null : new AdLabels( - translations.getLearnMoreLabel(), - translations.getAdsCountdownAdLabel(), - translations.getAdsCountdownOfLabel(), - translations.getSkipCountdownLabel(), - translations.getSkipLabel() - ); - AdGlobalSettings adGlobalSettings = new AdGlobalSettings(hideAdUiElements, isWhyThisAdIconEnabled, adLabels); - long dvrSeekBackwardInterval = src.getDvrSeekBackwardInterval(); long dvrSeekForwardInterval = src.getDvrSeekForwardInterval(); @@ -540,10 +530,9 @@ private void doInitializePlayer(boolean force) { dvrSeekBackwardInterval != 0L ? dvrSeekBackwardInterval : exoDorisPlayerView.getRewindIncrementMs(), adViewProvider, exoDorisPlayerView, - adGlobalSettings, src.getTracksPolicy()); - player.setDorisListener(dorisListener); + player.setOutput(dorisListener); trackSelector = player.getTrackSelector(); ExoPlayer exoPlayer = player.getExoPlayer(); @@ -574,6 +563,18 @@ private void doInitializePlayer(boolean force) { showOverlay(); showWatermark(); + AdLabels adLabels = translations == null ? null : new AdLabels( + translations.getLearnMoreLabel(), + translations.getAdsCountdownAdLabel(), + translations.getAdsCountdownOfLabel(), + translations.getSkipCountdownLabel(), + translations.getSkipLabel() + ); + AdGlobalSettings adGlobalSettings = new AdGlobalSettings.Builder() + .setHideAdUiElements(hideAdUiElements) + .setWhyThisAdIconEnabled(isWhyThisAdIconEnabled) + .setAdLabels(adLabels) + .build(); SourceBuilder sourceBuilder = new SourceBuilder(); if (adType == AdType.IMA_DAI) { ImaDaiProperties imaDaiProperties = new ImaDaiPropertiesBuilder() @@ -595,6 +596,7 @@ private void doInitializePlayer(boolean force) { .setUrl(src.getUrl()) .setMimeType(src.getMimeType()) .setYoSsaiProperties(src.getYoSsai()) + .setAdGlobalSettings(adGlobalSettings) .setTextTracks(src.getTextTracks()) .setDrmParams(actionToken); @@ -759,7 +761,6 @@ private ApsSource createApsSource() { @Nullable private TextTrack[] getTextTracks(ReadableArray textTracks) { - LocalizationService localizationService = new LocalizationService(Locale.getDefault()); if (textTracks != null && textTracks.size() > 0) { TextTrack[] dorisTextTracks = new TextTrack[textTracks.size()]; for (int i = 0; i < textTracks.size(); ++i) { @@ -767,7 +768,7 @@ private TextTrack[] getTextTracks(ReadableArray textTracks) { String uri = textTrack.getString("uri"); String isoCode = textTrack.getString("language"); String name = isoCode != null - ? localizationService.getLocalizedLanguageLabel(isoCode, true) + ? localizationService.getLocalizedLanguageLabel(isoCode) : null; dorisTextTracks[i] = new TextTrack( Uri.parse(uri), @@ -1474,14 +1475,14 @@ private void selectTrack(TracksPolicy.TrackPolicy trackPolicy, int trackType, @N if (trackType == C.TRACK_TYPE_TEXT) { if (preferredLanguages == null || preferredLanguages.isEmpty() || preferredLanguages.get(0) == null) { // "OFF" or user not select preferred subtitle if (trackPolicy != null) { // track policy is active, select track policy subtitle - track = TrackUtils.findMatchingTrack(trackList, trackType, trackPolicy.getSubtitle()); + track = TrackUtils.findMatchingTrack(localizationService, trackList, trackType, trackPolicy.getSubtitle()); } } else { // select user preferred subtitle - track = TrackUtils.findMatchingTrack(trackList, trackType, preferredLanguages.get(0)); + track = TrackUtils.findMatchingTrack(localizationService, trackList, trackType, preferredLanguages.get(0)); } } else if (trackType == C.TRACK_TYPE_AUDIO) { if (preferredLanguages != null && !preferredLanguages.isEmpty() && preferredLanguages.get(0) != null) { - track = TrackUtils.findMatchingTrack(trackList, trackType, preferredLanguages.get(0)); + track = TrackUtils.findMatchingTrack(localizationService, trackList, trackType, preferredLanguages.get(0)); } } if (track != null) { @@ -1499,7 +1500,7 @@ private List getTracks(Tracks tracksInfo) { Format format = group.getFormat(0); String name = TrackUtils.getTrackName(group, trackType); String language = format.language; - trackSet.add(new Track(trackType, name, language, isSelected)); + trackSet.add(new Track(format.id, trackType, name, language, isSelected)); } } return new ArrayList<>(trackSet); @@ -2004,7 +2005,7 @@ public void onPlayerEvent(DorisPlayerEvent playerEvent) { reloadCurrentSource(); break; case ERROR: - Exception error = playerEvent.details.error; + Exception error = playerEvent.details.error == null ? null : playerEvent.details.error.getException(); if (error instanceof PlaybackException) { handlePlaybackError((PlaybackException) error); } else if (error != null) { @@ -2050,7 +2051,7 @@ public void onAdEvent(DorisAdEvent adEvent) { case AD_LOADING: // PlayerView does not expose SurfaceView, we should call setVisibility() and setPlayer(). if (isCsaiLiveEvent(adEvent)) { - secondaryPlayerView.setPlayer(((ExoDorisImaCsaiLivePlayer) player).getLiveAdExoPlayer()); + secondaryPlayerView.setPlayer(player.getDorisExtension() == null ? null : player.getDorisExtension().getSecondaryAdPlayer()); } break; case AD_MARKERS_CHANGED: diff --git a/android-exoplayer/src/main/java/com/dice/messaging/DiceMessageEx.kt b/android-exoplayer/src/main/java/com/dice/messaging/DiceMessageEx.kt index b25af2a5f1..890cbca7d1 100644 --- a/android-exoplayer/src/main/java/com/dice/messaging/DiceMessageEx.kt +++ b/android-exoplayer/src/main/java/com/dice/messaging/DiceMessageEx.kt @@ -69,6 +69,7 @@ internal fun Format.toMessagingTextTrack(src: String?) = PlayerTextTracksInfo.Te internal fun Format.toMediaTextTrack(selected: Boolean) = toMediaTrack(TRACK_TYPE_TEXT, selected) internal fun Format.toMediaTrack(type: Int, selected: Boolean) = Track( + id, type, label, language, diff --git a/android-exoplayer/src/main/java/com/dice/messaging/DorisPlayerEx.kt b/android-exoplayer/src/main/java/com/dice/messaging/DorisPlayerEx.kt index 938a589479..6193fad6e3 100644 --- a/android-exoplayer/src/main/java/com/dice/messaging/DorisPlayerEx.kt +++ b/android-exoplayer/src/main/java/com/dice/messaging/DorisPlayerEx.kt @@ -75,8 +75,10 @@ internal fun Group.filterFormatIndexed(predicate: (Int, Format) -> Boolean): Lis internal fun createOffTextTrack(isSelected: Boolean = true): Track = createOffTrack(TRACK_TYPE_TEXT, isSelected) internal fun createOffAudioTrack(isSelected: Boolean = true): Track = createOffTrack(TRACK_TYPE_AUDIO, isSelected) +internal const val ID_OFF = "-999" internal const val OFF_TRACK_NAME = "OFF" internal fun createOffTrack(trackType: Int, isSelected: Boolean = true): Track = Track( + /* id = */ ID_OFF, /* trackType = */ trackType, /* name = */ OFF_TRACK_NAME, /* language = */ "", diff --git a/package.json b/package.json index 40a20d9cd5..b271f40789 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-video", "version": "7.5.30", - "dorisAndroidVersion": "3.11.5", + "dorisAndroidVersion": "be3e3a8bc3", "description": "A