Skip to content

Commit

Permalink
chore(android): move contentStartTime into source prop (#4160)
Browse files Browse the repository at this point in the history
  • Loading branch information
freeboub authored Sep 14, 2024
1 parent b74cb59 commit 24d90e9
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 19 deletions.
6 changes: 6 additions & 0 deletions android/src/main/java/com/brentvatne/common/api/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -79,6 +82,7 @@ class Source {
startPositionMs == other.startPositionMs &&
extension == other.extension &&
drmProps == other.drmProps &&
contentStartTime == other.contentStartTime &&
cmcdProps == other.cmcdProps &&
sideLoadedTextTracks == other.sideLoadedTextTracks
)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1436,7 +1435,7 @@ private void videoLoaded() {
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
Expand Down Expand Up @@ -1539,7 +1538,7 @@ private ArrayList<VideoTrack> getVideoTrackInfoFromManifest(int retryCount) {
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;
Expand Down Expand Up @@ -2207,10 +2206,6 @@ public void setFocusable(boolean focusable) {
exoPlayerView.setFocusable(this.focusable);
}

public void setContentStartTime(int contentStartTime) {
this.contentStartTime = contentStartTime;
}

public void setShowNotificationControls(boolean showNotificationControls) {
this.showNotificationControls = showNotificationControls;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions docs/pages/component/props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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']} />

Expand Down
14 changes: 11 additions & 3 deletions examples/basic/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>
)}
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/src/constants/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 6 additions & 1 deletion src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
poster,
posterResizeMode,
renderLoader,
contentStartTime,
drm,
textTracks,
selectedVideoTrack,
Expand Down Expand Up @@ -204,6 +205,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
}
}

const selectedContentStartTime =
source.contentStartTime || contentStartTime;

return {
uri,
isNetwork,
Expand All @@ -216,14 +220,15 @@ 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,
textTracks: _textTracks,
textTracksAllowChunklessPreparation:
resolvedSource.textTracksAllowChunklessPreparation,
};
}, [drm, source, textTracks]);
}, [drm, source, textTracks, contentStartTime]);

const _selectedTextTrack = useMemo(() => {
if (!selectedTextTrack) {
Expand Down
2 changes: 1 addition & 1 deletion src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type VideoSrc = Readonly<{
startPosition?: Float;
cropStart?: Float;
cropEnd?: Float;
contentStartTime?: Int32; // Android
metadata?: VideoMetadata;
drm?: Drm;
cmcd?: NativeCmcdConfiguration; // android
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/types/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type ReactVideoSourceProperties = {
startPosition?: number;
cropStart?: number;
cropEnd?: number;
contentStartTime?: number; // Android
metadata?: VideoMetadata;
drm?: Drm;
cmcd?: Cmcd; // android
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 24d90e9

Please sign in to comment.