Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply doris-android 4.x (vesper branch) #381

Draft
wants to merge 3 commits into
base: super/dicetechnology
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.brentvatne.exoplayer;

import static androidx.media3.common.util.Assertions.checkNotNull;

import android.content.Context;

import androidx.annotation.NonNull;
Expand All @@ -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 {

Expand All @@ -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,
Expand All @@ -44,10 +33,8 @@ public ExoDoris createPlayer(
forwardIncrementMs,
rewindIncrementMs,
null,
null,
adViewProvider,
adChoicesTvListener,
adGlobalSettings,
adChoicesClickViewRenderer,
tracksPolicy);
}

Expand All @@ -59,37 +46,21 @@ public ExoDoris createPlayer(
int loadBufferMs,
long forwardIncrementMs,
long rewindIncrementMs,
@Nullable List<Plugin> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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()
Expand All @@ -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);

Expand Down Expand Up @@ -759,15 +761,14 @@ 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) {
ReadableMap textTrack = textTracks.getMap(i);
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),
Expand Down Expand Up @@ -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) {
Expand All @@ -1499,7 +1500,7 @@ private List<Track> 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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = */ "",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-video",
"version": "7.5.33",
"dorisAndroidVersion": "3.11.10",
"dorisAndroidVersion": "4.0.14",
"description": "A <Video /> element for react-native",
"main": "Video.tsx",
"license": "MIT",
Expand Down