Skip to content

Commit 4640177

Browse files
fix: support shouldAutoStart from video data config (#469)
* fix: support shouldAutoStart from video data config * chore: bump rndv * fix: add shouldAutoStart param to control when to start video (#470) * chore: bump doris android --------- Co-authored-by: Wei.Liu <[email protected]>
1 parent 85af314 commit 4640177

File tree

10 files changed

+58
-11
lines changed

10 files changed

+58
-11
lines changed

android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class ReactTVExoplayerView extends FrameLayout implements LifecycleEventListener
206206
private boolean hideAdUiElements;
207207
private boolean isWhyThisAdIconEnabled;
208208
private boolean isPlayPauseEnabled = true;
209+
private boolean shouldAutoStart = true;
209210
private float jsProgressUpdateInterval = 250.0f;
210211
// \ End props
211212

@@ -551,9 +552,12 @@ private void doInitializePlayer(boolean force) {
551552
player = exoDorisFactory.createPlayer(
552553
getContext(),
553554
adType,
555+
shouldAutoStart,
556+
null,
554557
MAX_LOAD_BUFFER_MS,
555558
dvrSeekForwardInterval != 0L ? dvrSeekForwardInterval : exoDorisPlayerView.getFastForwardIncrementMs(),
556559
dvrSeekBackwardInterval != 0L ? dvrSeekBackwardInterval : exoDorisPlayerView.getRewindIncrementMs(),
560+
null,
557561
adViewProvider,
558562
exoDorisPlayerView,
559563
src.getTracksPolicy());
@@ -608,6 +612,7 @@ private void doInitializePlayer(boolean force) {
608612
sourceBuilder
609613
.setId(src.getId())
610614
.setUrl(src.getUrl())
615+
.setShouldPlayWhenReady(shouldAutoStart)
611616
.setMimeType(src.getMimeType())
612617
.setYoSsaiProperties(src.getYoSsai())
613618
.setAmtSsaiProperties(src.getAmtSsai())
@@ -1881,6 +1886,10 @@ public void setPlayPauseEnabled(boolean playPauseEnabled) {
18811886
exoDorisPlayerView.setPlayPauseEnabled(playPauseEnabled);
18821887
}
18831888

1889+
public void setShouldAutoStart(boolean shouldAutoStart) {
1890+
this.shouldAutoStart = shouldAutoStart;
1891+
}
1892+
18841893
private boolean isUnauthorizedAdError(Exception error) {
18851894
return error.getMessage().contains("HTTP status code: 403");
18861895
}

android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactTVExoplayerViewManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public class ReactTVExoplayerViewManager extends ViewGroupManager<ReactTVExoplay
148148
private static final String PROP_LOCALE = "locale";
149149
private static final String PROP_IS4K = "is4K";
150150
private static final String PROP_IS_PLAY_PAUSE_ENABLED = "isPlayPauseEnabled";
151+
private static final String PROP_SHOULD_AUTO_START = "shouldAutoStart";
151152

152153
private static final int COMMAND_SEEK_TO_POSITION = 4;
153154
private static final int COMMAND_REPLACE_AD_TAG_PARAMETERS = 5;
@@ -644,6 +645,11 @@ public void setIsPlayPauseEnabled(final ReactTVExoplayerView videoView, boolean
644645
videoView.setPlayPauseEnabled(isPlayPauseEnabled);
645646
}
646647

648+
@ReactProp(name = PROP_SHOULD_AUTO_START)
649+
public void setShouldAutoStart(final ReactTVExoplayerView videoView, boolean shouldAutoStart){
650+
videoView.setShouldAutoStart(shouldAutoStart);
651+
}
652+
647653
private boolean startsWithValidScheme(String uriString) {
648654
if (uriString == null) {
649655
return false;

ios/JSProps/JSProps.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class JSProps {
2424
var hideAdUiElements: Dynamic<Bool> = Dynamic(false)
2525
var isWhyThisAdIconEnabled: Dynamic<Bool> = Dynamic(false)
2626
var locale: Dynamic<String?> = Dynamic(nil)
27-
var isPlayPauseEnabled: Dynamic<Bool> = Dynamic(true)
27+
var isPlayPauseEnabled: Dynamic<Bool> = Dynamic(true)
28+
var shouldAutoStart: Dynamic<Bool> = Dynamic(true)
2829
}
2930

3031
class Dynamic<T> {

ios/Video/NewPlayerView.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class NewPlayerView: UIView, JSInputProtocol {
1515
//Events
1616
//used
1717
@objc var onBackButton: RCTBubblingEventBlock?
18+
@objc var onVideoLoadStart: RCTBubblingEventBlock?
1819
@objc var onVideoLoad: RCTBubblingEventBlock?
1920
@objc var onVideoError: RCTBubblingEventBlock?
2021
@objc var onVideoProgress: RCTBubblingEventBlock?
@@ -38,7 +39,6 @@ class NewPlayerView: UIView, JSInputProtocol {
3839
@objc var onPlayPauseAction: RCTBubblingEventBlock?
3940

4041
//not used
41-
@objc var onVideoLoadStart: RCTBubblingEventBlock?
4242
@objc var onTimedMetadata: RCTBubblingEventBlock?
4343
@objc var onVideoAudioBecomingNoisy: RCTBubblingEventBlock?
4444
@objc var onVideoFullscreenPlayerWillPresent: RCTBubblingEventBlock?
@@ -153,7 +153,13 @@ class NewPlayerView: UIView, JSInputProtocol {
153153
jsProps.isPlayPauseEnabled.value = isPlayPauseEnabled
154154
}
155155
}
156-
156+
157+
@objc var shouldAutoStart: Bool = true {
158+
didSet {
159+
jsProps.shouldAutoStart.value = shouldAutoStart
160+
}
161+
}
162+
157163
//FIXME: review unused variables
158164
@objc var selectedTextTrack: NSDictionary?
159165
@objc var selectedAudioTrack: NSDictionary?
@@ -206,7 +212,10 @@ class NewPlayerView: UIView, JSInputProtocol {
206212
jsPlayerView.onBackButton = self.onBackButton
207213
jsPlayerView.onVideoError = self.onVideoError
208214
jsPlayerView.onRequireAdParameters = self.onRequireAdParameters
209-
jsPlayerView.onVideoLoad = self.onVideoLoad
215+
// in RNDV, onVideoLoad fires when load initiated
216+
jsPlayerView.onVideoLoad = self.onVideoLoadStart
217+
// in RNDV, onVideoStart fires when the video loaded and about to play
218+
jsPlayerView.onVideoStart = self.onVideoLoad
210219
jsPlayerView.onSubtitleTrackChanged = self.onSubtitleTrackChanged
211220
jsPlayerView.onAudioTrackChanged = self.onAudioTrackChanged
212221
jsPlayerView.isMuted = self.muted

ios/Video/PlayerViewProxy.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ class PlayerViewProxy {
289289
seekBackwardInterval: seekBackwardInterval,
290290
hideAdUiElements: jsProps.hideAdUiElements.value,
291291
isWhyThisAdIconEnabled: jsProps.isWhyThisAdIconEnabled.value,
292-
isPlayPauseEnabled: jsProps.isPlayPauseEnabled.value)
293-
292+
isPlayPauseEnabled: jsProps.isPlayPauseEnabled.value,
293+
shouldAutoStart: jsProps.shouldAutoStart.value
294+
)
295+
294296
if let rndvJSSource = rndvJSSource {
295297
let jsVideoData = RNDReactNativeDiceVideo.JSVideoData(source: rndvJSSource, config: rndvJSVideoDataConfig)
296298
rndvJsProps.videoData.value = jsVideoData

ios/Video/RCTVideoManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ @interface RCT_EXTERN_MODULE(RCTVideoManager, RCTViewManager)
3434
RCT_EXPORT_VIEW_PROPERTY(isWhyThisAdIconEnabled, BOOL);
3535
RCT_EXPORT_VIEW_PROPERTY(locale, NSString);
3636
RCT_EXPORT_VIEW_PROPERTY(isPlayPauseEnabled, BOOL);
37+
RCT_EXPORT_VIEW_PROPERTY(shouldAutoStart, BOOL);
3738

3839
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
3940
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTBubblingEventBlock);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-video",
3-
"version": "7.12.19",
4-
"dorisAndroidVersion": "5.2.23",
3+
"version": "7.12.20",
4+
"dorisAndroidVersion": "5.2.25",
55
"messagingAndroidVersion": "1.1.0",
66
"description": "A <Video /> element for react-native",
77
"main": "Video.tsx",
@@ -21,7 +21,7 @@
2121
"eslint-plugin-react": "3.16.1"
2222
},
2323
"dependencies": {
24-
"@dicetechnology/react-native-dice-video": "git+ssh://[email protected]/DiceTechnology/react-native-dice-video.git#7.4.20",
24+
"@dicetechnology/react-native-dice-video": "git+ssh://[email protected]/DiceTechnology/react-native-dice-video.git#7.4.24",
2525
"@dicetechnology/dice-unity": "^2.26.3",
2626
"keymirror": "0.1.1",
2727
"prop-types": "^15.5.10"

types/callbacks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IVideoPlayerPlayPauseEvent, IVideoPlayerSeekEndedEvent } from "./event";
12
import { IVideoPlayerOnRequireAdParametersPayload } from "./ima";
23

34
export interface IVideoPlayerCallbacks {
@@ -18,7 +19,7 @@ export interface IVideoPlayerCallbacks {
1819
onRelatedVideosIconClicked?: (e: any) => void;
1920
onRequireAdParameters?: (e: IVideoPlayerOnRequireAdParametersPayload) => void;
2021
onSeek?: (e: any) => void;
21-
onSeekEndedEvent?: (e: any) => void;
22+
onSeekEndedEvent?: (e: IVideoPlayerSeekEndedEvent) => void;
2223
onStatsIconClick?: () => void;
2324
onTimedMetadata?: (e: any) => void;
2425
onVideoAboutToEnd?: (e: any) => void;
@@ -28,5 +29,5 @@ export interface IVideoPlayerCallbacks {
2829
onAudioTrackChanged?: ({ language }: { language: string }) => void;
2930
onSubtitleTrackChanged?: ({ language }: { language: string }) => void;
3031
onSkipMarkerButton?: (e: any) => void;
31-
onPlayPauseAction?: (e: any) => void;
32+
onPlayPauseAction?: (e: IVideoPlayerPlayPauseEvent) => void;
3233
}

types/event.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
export enum IVideoPlayerSeekType {
3+
SKIP = "skip",
4+
SEEK = "seek",
5+
GO_LIVE = "liveBadge",
6+
SKIP_MARKER = "skipMarker",
7+
}
8+
9+
export interface IVideoPlayerSeekEndedEvent {
10+
seekType: IVideoPlayerSeekType;
11+
seekStartAt: number;
12+
seekEndAt: number;
13+
};
14+
15+
export interface IVideoPlayerPlayPauseEvent {
16+
isPaused: boolean;
17+
};

types/player.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ export interface IVideoPlayer extends IVideoPlayerCallbacks, ViewProps {
4646
width?: number;
4747
subtitleHorizontalPadding?: number;
4848
isPlayPauseEnabled?: boolean;
49+
shouldAutoStart?: boolean;
4950
}

0 commit comments

Comments
 (0)