chore(android): move contentStartTime into source prop (#4160)

This commit is contained in:
Olivier Bouillet 2024-09-14 19:53:54 +02:00 committed by GitHub
parent b74cb59602
commit 24d90e9ec8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 40 additions and 19 deletions

View File

@ -38,6 +38,9 @@ class Source {
/** Will crop content end at specified position */
var cropEndMs: Int = -1
/** Will virtually consider that content before contentStartTime is a preroll ad */
var contentStartTime: Int = -1
/** Allow to force stream content, necessary when uri doesn't contain content type (.mlp4, .m3u, ...) */
var extension: String? = null
@ -79,6 +82,7 @@ class Source {
startPositionMs == other.startPositionMs &&
extension == other.extension &&
drmProps == other.drmProps &&
contentStartTime == other.contentStartTime &&
cmcdProps == other.cmcdProps &&
sideLoadedTextTracks == other.sideLoadedTextTracks
)
@ -139,6 +143,7 @@ class Source {
private const val PROP_SRC_START_POSITION = "startPosition"
private const val PROP_SRC_CROP_START = "cropStart"
private const val PROP_SRC_CROP_END = "cropEnd"
private const val PROP_SRC_CONTENT_START_TIME = "contentStartTime"
private const val PROP_SRC_TYPE = "type"
private const val PROP_SRC_METADATA = "metadata"
private const val PROP_SRC_HEADERS = "requestHeaders"
@ -201,6 +206,7 @@ class Source {
source.startPositionMs = safeGetInt(src, PROP_SRC_START_POSITION, -1)
source.cropStartMs = safeGetInt(src, PROP_SRC_CROP_START, -1)
source.cropEndMs = safeGetInt(src, PROP_SRC_CROP_END, -1)
source.contentStartTime = safeGetInt(src, PROP_SRC_CONTENT_START_TIME, -1)
source.extension = safeGetString(src, PROP_SRC_TYPE, null)
source.drmProps = parse(safeGetMap(src, PROP_SRC_DRM))
source.cmcdProps = CMCDProps.parse(safeGetMap(src, PROP_SRC_CMCD))

View File

@ -235,7 +235,6 @@ public class ReactExoplayerView extends FrameLayout implements
private boolean disableFocus;
private boolean focusable = true;
private BufferingStrategy.BufferingStrategyEnum bufferingStrategy;
private long contentStartTime = -1L;
private boolean disableDisconnectError;
private boolean preventsDisplaySleepDuringVideoPlayback = true;
private float mProgressUpdateInterval = 250.0f;
@ -1436,7 +1435,7 @@ public class ReactExoplayerView extends FrameLayout implements
ArrayList<Track> audioTracks = getAudioTrackInfo();
ArrayList<Track> textTracks = getTextTrackInfo();
if (this.contentStartTime != -1L) {
if (source.getContentStartTime() != -1) {
ExecutorService es = Executors.newSingleThreadExecutor();
es.execute(() -> {
// To prevent ANRs caused by getVideoTrackInfo we run this on a different thread and notify the player only when we're done
@ -1539,7 +1538,7 @@ public class ReactExoplayerView extends FrameLayout implements
ExecutorService es = Executors.newSingleThreadExecutor();
final DataSource dataSource = this.mediaDataSourceFactory.createDataSource();
final Uri sourceUri = source.getUri();
final long startTime = this.contentStartTime * 1000 - 100; // s -> ms with 100ms offset
final long startTime = source.getContentStartTime() * 1000 - 100; // s -> ms with 100ms offset
Future<ArrayList<VideoTrack>> result = es.submit(new Callable() {
final DataSource ds = dataSource;
@ -2207,10 +2206,6 @@ public class ReactExoplayerView extends FrameLayout implements
exoPlayerView.setFocusable(this.focusable);
}
public void setContentStartTime(int contentStartTime) {
this.contentStartTime = contentStartTime;
}
public void setShowNotificationControls(boolean showNotificationControls) {
this.showNotificationControls = showNotificationControls;

View File

@ -49,7 +49,6 @@ class ReactExoplayerViewManager(private val config: ReactExoplayerConfig) : View
private const val PROP_MIN_LOAD_RETRY_COUNT = "minLoadRetryCount"
private const val PROP_MAXIMUM_BIT_RATE = "maxBitRate"
private const val PROP_PLAY_IN_BACKGROUND = "playInBackground"
private const val PROP_CONTENT_START_TIME = "contentStartTime"
private const val PROP_DISABLE_FOCUS = "disableFocus"
private const val PROP_BUFFERING_STRATEGY = "bufferingStrategy"
private const val PROP_DISABLE_DISCONNECT_ERROR = "disableDisconnectError"
@ -237,11 +236,6 @@ class ReactExoplayerViewManager(private val config: ReactExoplayerConfig) : View
videoView.setFocusable(focusable)
}
@ReactProp(name = PROP_CONTENT_START_TIME, defaultInt = -1)
fun setContentStartTime(videoView: ReactExoplayerView, contentStartTime: Int) {
videoView.setContentStartTime(contentStartTime)
}
@ReactProp(name = PROP_BUFFERING_STRATEGY)
fun setBufferingStrategy(videoView: ReactExoplayerView, bufferingStrategy: String) {
val strategy = BufferingStrategy.parse(bufferingStrategy)

View File

@ -166,9 +166,13 @@ controlsStyles={{
### `contentStartTime`
> [!WARNING]
> Deprecated, use source.contentStartTime instead
<PlatformsList types={['Android']} />
The start time in ms for SSAI content. This determines at what time to load the video info like resolutions. Use this only when you have SSAI stream where ads resolution is not the same as content resolution.
Note: This feature only works on DASH streams
### `debug`
@ -833,6 +837,13 @@ source={{
}}
```
#### `contentStartTime`
<PlatformsList types={['Android']} />
The start time in ms for SSAI content. This determines at what time to load the video info like resolutions. Use this only when you have SSAI stream where ads resolution is not the same as content resolution.
Note: This feature only works on DASH streams
#### `textTracksAllowChunklessPreparation`
<PlatformsList types={['Android']} />

View File

@ -34,7 +34,12 @@ import Video, {
} from 'react-native-video';
import styles from './styles';
import {type AdditionalSourceInfo} from './types';
import {bufferConfig, isAndroid, srcList, textTracksSelectionBy} from './constants';
import {
bufferConfig,
isAndroid,
srcList,
textTracksSelectionBy,
} from './constants';
import {Overlay, toast, VideoLoader} from './components';
import * as NavigationBar from 'expo-navigation-bar';
@ -224,7 +229,7 @@ const VideoPlayer: FC<Props> = ({}) => {
const onVideoBandwidthUpdate = (data: OnBandwidthUpdateData) => {
console.log('onVideoBandwidthUpdate', data);
}
};
const onFullScreenExit = () => {
// iOS pauses video on exit from full screen
@ -284,7 +289,10 @@ const VideoPlayer: FC<Props> = ({}) => {
bufferingStrategy={BufferingStrategyType.DEFAULT}
debug={{enable: true, thread: true}}
subtitleStyle={{subtitlesFollowVideo: true}}
controlsStyles={{hideNavigationBarOnFullScreenMode: true, hideNotificationBarOnFullScreenMode: true}}
controlsStyles={{
hideNavigationBarOnFullScreenMode: true,
hideNotificationBarOnFullScreenMode: true,
}}
/>
</TouchableOpacity>
)}

View File

@ -12,7 +12,7 @@ import {Platform} from 'react-native';
// This constant allows to change how the sample behaves regarding to texts selection.
// You can change it to change how selector will use tracks information.
// by default, index will be displayed and index will be applied to selected tracks.
// You can also use LANGUAGE or TITLE
// You can also use LANGUAGE or TITLE
export const textTracksSelectionBy = SelectedTrackType.INDEX;
export const isIos = Platform.OS === 'ios';

View File

@ -79,6 +79,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
poster,
posterResizeMode,
renderLoader,
contentStartTime,
drm,
textTracks,
selectedVideoTrack,
@ -204,6 +205,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
}
}
const selectedContentStartTime =
source.contentStartTime || contentStartTime;
return {
uri,
isNetwork,
@ -216,6 +220,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
startPosition: resolvedSource.startPosition ?? -1,
cropStart: resolvedSource.cropStart || 0,
cropEnd: resolvedSource.cropEnd,
contentStartTime: selectedContentStartTime,
metadata: resolvedSource.metadata,
drm: _drm,
cmcd: _cmcd,
@ -223,7 +228,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
textTracksAllowChunklessPreparation:
resolvedSource.textTracksAllowChunklessPreparation,
};
}, [drm, source, textTracks]);
}, [drm, source, textTracks, contentStartTime]);
const _selectedTextTrack = useMemo(() => {
if (!selectedTextTrack) {

View File

@ -38,6 +38,7 @@ export type VideoSrc = Readonly<{
startPosition?: Float;
cropStart?: Float;
cropEnd?: Float;
contentStartTime?: Int32; // Android
metadata?: VideoMetadata;
drm?: Drm;
cmcd?: NativeCmcdConfiguration; // android
@ -344,7 +345,6 @@ export interface VideoNativeProps extends ViewProps {
debug?: DebugConfig;
showNotificationControls?: WithDefault<boolean, false>; // Android, iOS
bufferConfig?: BufferConfig; // Android
contentStartTime?: Int32; // Android
currentPlaybackTime?: Double; // Android
disableDisconnectError?: boolean; // Android
focusable?: boolean; // Android

View File

@ -31,6 +31,7 @@ export type ReactVideoSourceProperties = {
startPosition?: number;
cropStart?: number;
cropEnd?: number;
contentStartTime?: number; // Android
metadata?: VideoMetadata;
drm?: Drm;
cmcd?: Cmcd; // android
@ -265,6 +266,7 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
bufferConfig?: BufferConfig; // Android
bufferingStrategy?: BufferingStrategyType;
chapters?: Chapters[]; // iOS
/** @deprecated Use source.contentStartTime */
contentStartTime?: number; // Android
controls?: boolean;
currentPlaybackTime?: number; // Android