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

Feat/doris 2706 audio only UI #396

Merged
merged 11 commits into from
Jan 13, 2025
Merged

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.amazon.device.ads.aftv.AmazonFireTVAdsKeyValuePair;
import com.brentvatne.entity.ApsSource;
import com.brentvatne.entity.RNImaDaiSource;
import com.brentvatne.entity.RNMetadata;
import com.brentvatne.entity.RNSource;
import com.brentvatne.entity.RelatedVideo;
import com.brentvatne.entity.Watermark;
Expand Down Expand Up @@ -84,6 +83,7 @@
import com.diceplatform.doris.entity.YoSsaiProperties;
import com.diceplatform.doris.ext.imacsailive.ExoDorisImaCsaiLivePlayer;
import com.diceplatform.doris.internal.ResumePositionHandler;
import com.diceplatform.doris.sourceresolver.ContentMetadata;
import com.diceplatform.doris.ui.ExoDorisPlayerTvControlView;
import com.diceplatform.doris.ui.ExoDorisPlayerView;
import com.diceplatform.doris.ui.ExoDorisPlayerViewListener;
Expand Down Expand Up @@ -140,6 +140,9 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener

private static final int SECONDS_IN_30_MINUTES = 1800;
private static final int SECONDS_IN_60_MINUTES = 3600;
private static final int MAX_LOAD_BUFFER_MS = 30_000;
private static final int SHOW_JS_PROGRESS = 1;
private static final int SHOW_NATIVE_PROGRESS = 2;

// APS
private static final String APS_APP_ID = "1a0f83d069f04b8abc59bdf5176e6103";
Expand All @@ -150,23 +153,17 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener
private static final String APS_VOD_CHANNEL_NAME = "PrendeTV";
private static final String APS_VIDEO_CONTENT_ROOT_ELEMENT = "content";

private static final CookieManager DEFAULT_COOKIE_MANAGER;
private static final int SHOW_JS_PROGRESS = 1;
private static final int SHOW_NATIVE_PROGRESS = 2;

private static final String KEY_FIRST_CATEGORY = "first_category=";
private static final String KEY_RATING = "rating=";
private static final String KEY_AD_TAG_PARAMETERS = "adTagParameters";
private static final String KEY_START_DATE = "startDate";
private static final String KEY_END_DATE = "endDate";
private static final String KEY_METADATA_DESCRIPTION = "description";
private static final String KEY_METADATA_THUMBNAIL_URL = "thumbnailUrl";
private static final String KEY_METADATA_TYPE = "type";
private static final String KEY_METADATA_EPISODE_INFO = "episodeInfo";

private static final String KEY_LABELS_LEARN_MORE = "learnMore";
private static final String KEY_LABELS_COUNT_DOWN_AD = "adsCountdownAd";
private static final String KEY_LABELS_COUNT_DOWN_OF = "adsCountdownOf";
private static final String KEY_LABELS_SKIP_IN = "skipAdIn";
private static final String KEY_LABELS_SKIP = "skipAd";

private static final int MAX_LOAD_BUFFER_MS = 30_000;
private static final CookieManager DEFAULT_COOKIE_MANAGER;

static {
DEFAULT_COOKIE_MANAGER = new CookieManager();
Expand All @@ -181,7 +178,6 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener
private ExoDoris player;
private ExoDorisTrackSelector trackSelector;
private Source source;
private LocalizationService localizationService;
private boolean playerNeedsSource;
private long resumePosition; // unit: millisecond
private boolean loadVideoStarted;
Expand All @@ -202,7 +198,7 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener

// Props from React
private RNSource src;
private RNMetadata metadata;
private ContentMetadata metadata;
private boolean repeat;
private boolean disableFocus;
private boolean isLive = false;
Expand Down Expand Up @@ -365,7 +361,6 @@ public ReactTVExoplayerView(ThemedReactContext context) {

mediaSession = new MediaSessionCompat(getContext(), getContext().getPackageName());
mediaSessionConnector = new MediaSessionConnector(mediaSession);
localizationService = new LocalizationService(Locale.getDefault());

boolean isRTL = I18nUtil.getInstance().isRTL(getContext());
ExoDorisPlayerTvControlView controller = exoDorisPlayerView.findViewById(R.id.exo_controller);
Expand All @@ -374,7 +369,6 @@ public ReactTVExoplayerView(ThemedReactContext context) {
playList.setLayoutDirection(isRTL ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
}


@Override
public void setId(int id) {
super.setId(id);
Expand Down Expand Up @@ -527,15 +521,7 @@ private void doInitializePlayer(boolean force) {
AdViewProvider adViewProvider = adType == AdType.IMA_CSAI_LIVE
? secondaryPlayerView
: exoDorisPlayerView;
LabelsTranslation translations = exoDorisPlayerView.getLabelsTranslation();
AdLabels adLabels = translations == null ? null : new AdLabels(
translations.get(KEY_LABELS_LEARN_MORE),
translations.get(KEY_LABELS_COUNT_DOWN_AD),
translations.get(KEY_LABELS_COUNT_DOWN_OF),
translations.get(KEY_LABELS_SKIP_IN),
translations.get(KEY_LABELS_SKIP)
);
AdGlobalSettings adGlobalSettings = new AdGlobalSettings(hideAdUiElements, isWhyThisAdIconEnabled, adLabels);
AdGlobalSettings adGlobalSettings = getAdGlobalSettings();

long dvrSeekBackwardInterval = src.getDvrSeekBackwardInterval();
long dvrSeekForwardInterval = src.getDvrSeekForwardInterval();
Expand Down Expand Up @@ -645,6 +631,19 @@ private void doInitializePlayer(boolean force) {
}
}

@NonNull
private AdGlobalSettings getAdGlobalSettings() {
LabelsTranslation translations = exoDorisPlayerView.getLabelsTranslation();
AdLabels adLabels = translations == null ? null : new AdLabels(
translations.getAdLearnMore(),
translations.getAdCountDown(),
translations.getAdSCountDownOf(),
translations.getAdSkipCountDown(),
translations.getAdSkip()
);
return new AdGlobalSettings(hideAdUiElements, isWhyThisAdIconEnabled, adLabels);
}

private List<String> getPreferredSubtitleLang() {
TrackPreferenceStorage trackPreferenceStorage = TrackPreferenceStorage.getInstance(getContext());
if (!trackPreferenceStorage.isEnabled()) {
Expand Down Expand Up @@ -1292,8 +1291,8 @@ private void handlePlaybackError(PlaybackException error) {

private void reloadCurrentSource() {
if (src != null && metadata != null) {
Log.i(TAG, "Reload current source, id " + src.getId() + ", type " + metadata.getType());
eventEmitter.reloadCurrentSource(src.getId(), metadata.getType());
Log.i(TAG, "Reload current source, id " + src.getId() + ", type " + metadata.type);
eventEmitter.reloadCurrentSource(src.getId(), metadata.type);
return;
}
Log.i(TAG, "Reload current source, ignored for src or metadata is null");
Expand Down Expand Up @@ -1408,12 +1407,16 @@ public void setSrc(
}
}

public void setMetadata(RNMetadata metadata) {
this.metadata = metadata;
public void setMetadata(Map<String, String> map) {
this.metadata = new ContentMetadata.Builder()
.setThumbnailUrl(map.get(KEY_METADATA_THUMBNAIL_URL))
.setEpisodeTitle(map.get(KEY_METADATA_EPISODE_INFO))
.setDescription(map.get(KEY_METADATA_DESCRIPTION))
.setType(map.get(KEY_METADATA_TYPE))
.build();

if (exoDorisPlayerView != null) {
exoDorisPlayerView.setEpisodeTitle(metadata.getEpisodeTitle());
exoDorisPlayerView.setDescription(metadata.getDescription());
exoDorisPlayerView.setMetadata(metadata);
}
}

Expand Down Expand Up @@ -1460,6 +1463,7 @@ public void setRawSrc(@NonNull final Uri uri, @Nullable final String extension)
}
}

@SuppressLint("WrongConstant")
public void setResizeModeModifier(@ResizeMode.Mode int resizeMode) {
exoDorisPlayerView.setResizeMode(resizeMode);
}
Expand Down Expand Up @@ -1765,6 +1769,12 @@ public void setAppLanguageLocale(String locale) {
}
}

public void setAudioOnly(boolean audioOnly) {
if (exoDorisPlayerView != null) {
exoDorisPlayerView.setAudioOnly(audioOnly);
}
}

private boolean getEnabledFromState(String stateStr) {
ControlState state = ControlState.make(stateStr);
switch (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import androidx.media3.datasource.RawResourceDataSource;
import androidx.media3.exoplayer.DefaultLoadControl;

import com.brentvatne.entity.RNMetadata;
import com.brentvatne.entity.RelatedVideo;
import com.brentvatne.entity.Watermark;
import com.brentvatne.react.BuildConfig;
Expand Down Expand Up @@ -45,6 +44,9 @@

import javax.annotation.Nullable;

/**
* @noinspection ALL
*/
public class ReactTVExoplayerViewManager extends ViewGroupManager<ReactTVExoplayerView> {

private static final String REACT_CLASS = "RCTVideo";
Expand Down Expand Up @@ -80,6 +82,7 @@ public class ReactTVExoplayerViewManager extends ViewGroupManager<ReactTVExoplay
private static final String PROP_SRC_DVR_SEEK_FORWARD_INTERVAL = "dvrSeekForwardInterval";
private static final String PROP_SRC_PLUGINS = "plugins";
private static final String PROP_SRC_LIVE = "live";
private static final String PROP_SRC_AUDIO_ONLY = "isAudioOnly";

// Metadata properties
private static final String PROP_METADATA = "metadata";
Expand Down Expand Up @@ -230,6 +233,7 @@ public void setSrc(final ReactTVExoplayerView videoView, @Nullable ReadableMap s

String uriString = src.hasKey(PROP_SRC_URI) ? src.getString(PROP_SRC_URI) : null;
String mimeType = ReadableMapUtils.getString(src, PROP_SRC_CONTENT_TYPE);
boolean isAudioOnly = ReadableMapUtils.getBoolean(src, PROP_SRC_AUDIO_ONLY);
String id = src.hasKey(PROP_SRC_ID) ? src.getString(PROP_SRC_ID) : null;
ReadableArray textTracks = src.hasKey(PROP_SRC_SUBTITLES) ? src.getArray(PROP_SRC_SUBTITLES) : null;
String extension = src.hasKey(PROP_SRC_TYPE) ? src.getString(PROP_SRC_TYPE) : null;
Expand Down Expand Up @@ -327,6 +331,8 @@ public void setSrc(final ReactTVExoplayerView videoView, @Nullable ReadableMap s
(actionToken == null ? "-" : actionToken.getLicensingServerUrl()),
uriString));

videoView.setAudioOnly(isAudioOnly);

videoView.setSrc(
uriString,
mimeType,
Expand Down Expand Up @@ -380,12 +386,7 @@ public void setSrc(final ReactTVExoplayerView videoView, @Nullable ReadableMap s
@ReactProp(name = PROP_METADATA)
public void setMetadata(final ReactTVExoplayerView videoView, final ReadableMap metadata) {
if (metadata != null) {
String description = metadata.hasKey(PROP_METADATA_DESCRIPTION) ? metadata.getString(PROP_METADATA_DESCRIPTION) : null;
String thumbnailUrl = metadata.hasKey(PROP_METADATA_THUMBNAIL_URL) ? metadata.getString(PROP_METADATA_THUMBNAIL_URL) : null;
String type = metadata.hasKey(PROP_METADATA_TYPE) ? metadata.getString(PROP_METADATA_TYPE) : null;
String episodeTitle = metadata.hasKey(PROP_METADATA_EPISODE_INFO) ? metadata.getString(PROP_METADATA_EPISODE_INFO) : null;

videoView.setMetadata(new RNMetadata(description, thumbnailUrl, episodeTitle, type));
videoView.setMetadata(toStringMap(metadata));
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-video",
"version": "7.6.0",
"dorisAndroidVersion": "3.12.3",
"version": "7.6.1",
"dorisAndroidVersion": "3.12.4",
"description": "A <Video /> element for react-native",
"main": "Video.tsx",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions types/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ export interface IVideoPlayerSource {
dvrSeekBackwardInterval?: number;
plugins?: IPlugins;
live?: boolean;
isAudioOnly?: boolean;
}