Skip to content

Commit a244edf

Browse files
smlrqguoen21NickWang618
authored
[No ticket] Replace seekToResume with resumePosition (#441)
* fix: replace seekToResume with src.resumePosition * fix: clean up SeekToCommand enum * fix:Replace seek to resume with resume position in native player * Revert "fix:Replace seek to resume with resume position in native player" This reverts commit 16bb6e1. * Reapply "fix:Replace seek to resume with resume position in native player" This reverts commit 9697ff7. * chore: apply the changes of move resume position to src for android part (#442) * chore: apply the changes of move resume position to src for android part * chore: bump version --------- Co-authored-by: Guoen Yong <guoen.yong@endeavorstreaming.com> Co-authored-by: Nick Wang <nick.wang@endeavorstreaming.com>
1 parent 302c288 commit a244edf

12 files changed

Lines changed: 27 additions & 125 deletions

File tree

Video.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,34 +145,6 @@ export default class Video extends React.PureComponent<IVideoPlayer, IState> {
145145
this.props.onBehindLiveWindowError?.(event.nativeEvent);
146146
}
147147

148-
/**
149-
* seekToResume jumps to a certain position for vod and live content
150-
* time parameter can be the following:
151-
* string: unix timestamp (used for live annotation)
152-
* number: seconds elapsed (used for vod annotation)
153-
* now: for DVR content to jump back to current live time
154-
*/
155-
seekToResume = (time: 'now' | string | number) => {
156-
let command = SeekToCommand.SEEK_TO_NOW;
157-
const args: Array<string | number> = [];
158-
159-
if (time !== 'now') {
160-
command =
161-
typeof time === 'string'
162-
? SeekToCommand.SEEK_TO_TIMESTAMP
163-
: SeekToCommand.SEEK_TO_RESUME_POSITION;
164-
args.push(time);
165-
}
166-
167-
if (this.refPlayer) {
168-
NativeModules.UIManager.dispatchViewManagerCommand(
169-
findNodeHandle(this.refPlayer.current),
170-
NativeModules.UIManager.RCTVideo.Commands[command],
171-
args
172-
);
173-
}
174-
};
175-
176148
/**
177149
* @description seeks to a specified time in the video
178150
* @param time video time in seconds

android-exoplayer/src/main/java/com/brentvatne/entity/RNSource.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class RNSource {
4242
private final YoSsaiProperties yoSsai;
4343
private final AmtSsaiProperties amtSsai;
4444
private final LimitedSeekRange limitedSeekRange;
45+
private final long resumePosition;
4546
private final TracksPolicy tracksPolicy;
4647
private final long dvrSeekForwardInterval;
4748
private final long dvrSeekBackwardInterval;
@@ -69,6 +70,7 @@ public RNSource(
6970
@Nullable YoSsaiProperties yoSsai,
7071
@Nullable AmtSsaiProperties amtSsai,
7172
@Nullable LimitedSeekRange limitedSeekRange,
73+
long resumePosition,
7274
TracksPolicy tracksPolicy,
7375
long dvrSeekForwardInterval,
7476
long dvrSeekBackwardInterval) {
@@ -95,6 +97,7 @@ public RNSource(
9597
this.yoSsai = yoSsai;
9698
this.amtSsai = amtSsai;
9799
this.limitedSeekRange = limitedSeekRange;
100+
this.resumePosition = resumePosition;
98101
this.tracksPolicy = tracksPolicy;
99102
this.dvrSeekForwardInterval = TimeUnit.SECONDS.toMillis(dvrSeekForwardInterval);
100103
this.dvrSeekBackwardInterval = TimeUnit.SECONDS.toMillis(dvrSeekBackwardInterval);
@@ -224,6 +227,10 @@ public LimitedSeekRange getLimitedSeekRange() {
224227
return limitedSeekRange;
225228
}
226229

230+
public long getResumePosition() {
231+
return resumePosition;
232+
}
233+
227234
public TracksPolicy getTracksPolicy() {
228235
return tracksPolicy;
229236
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,9 @@ private void doInitializePlayer(boolean force) {
621621
if (limitedSeekRange != null) {
622622
sourceBuilder.setLimitedSeekRange(limitedSeekRange);
623623
} else {
624-
sourceBuilder.setResumePosition(resumePosition);
624+
sourceBuilder.setResumePosition(src.getResumePosition());
625625
}
626+
clearResumePosition();
626627
source = sourceBuilder.build();
627628

628629
playerInitTime = new Date().getTime();
@@ -1317,6 +1318,7 @@ public void setSrc(
13171318
boolean apsTestFlag,
13181319
Watermark watermark,
13191320
LimitedSeekRange limitedSeekRange,
1321+
long resumePosition,
13201322
boolean shouldSaveSubtitleSelection,
13211323
String selectedSubtitleTrack,
13221324
List<String> preferredAudioTracks,
@@ -1368,6 +1370,7 @@ public void setSrc(
13681370
yoSsai,
13691371
amtSsai,
13701372
limitedSeekRange,
1373+
resumePosition,
13711374
tracksPolicy,
13721375
dvrSeekForwardInterval,
13731376
dvrSeekBackwardInterval);

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

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class ReactTVExoplayerViewManager extends ViewGroupManager<ReactTVExoplay
7373
private static final String PROP_SRC_APS_TEST_MODE = "testMode";
7474
private static final String PROP_SRC_METADATA = "metadata";
7575
private static final String PROP_SRC_LIMIT_RANGE = "limitedSeekableRange";
76+
private static final String PROP_SRC_RESUME_POSITION = "resumePosition";
7677
private static final String PROP_SRC_SAVE_SUBTITLE_SELECTION = "shouldSaveSubtitleSelection";
7778
private static final String PROP_SRC_NOW_PLAYING = "nowPlaying";
7879
private static final String PROP_SRC_BIF_URL = "thumbnailsPreview";
@@ -260,6 +261,13 @@ public void setSrc(final ReactTVExoplayerView videoView, @Nullable ReadableMap s
260261
boolean apsTestMode = (aps != null && aps.hasKey(PROP_SRC_APS_TEST_MODE)) && aps.getBoolean(PROP_SRC_APS_TEST_MODE);
261262

262263
LimitedSeekRange limitedSeekRange = generateRange(src.hasKey(PROP_SRC_LIMIT_RANGE) ? src.getMap(PROP_SRC_LIMIT_RANGE) : null);
264+
long resumePosition = ResumePositionHandler.RESUME_UNSET;
265+
if (src.hasKey(PROP_SRC_RESUME_POSITION) && !src.isNull(PROP_SRC_RESUME_POSITION)) {
266+
long rawPosition = Math.round(src.getDouble(PROP_SRC_RESUME_POSITION));
267+
if (rawPosition > 0) {
268+
resumePosition = (videoView.isLive() ? rawPosition : rawPosition * 1000);
269+
}
270+
}
263271
boolean shouldSaveSubtitleSelection = src.hasKey(PROP_SRC_SAVE_SUBTITLE_SELECTION) && src.getBoolean(PROP_SRC_SAVE_SUBTITLE_SELECTION);
264272

265273
if (src.hasKey(PROP_SRC_NOW_PLAYING)) {
@@ -322,10 +330,11 @@ public void setSrc(final ReactTVExoplayerView videoView, @Nullable ReadableMap s
322330
ImaCsaiProperties imaCsai = (ImaCsaiProperties) adProperties[0];
323331
TracksPolicy tracksPolicy = ReactTVPropsParser.parseTracksPolicy(ReadableMapUtils.getMap(src, "tracksPolicy"));
324332

325-
Log.i(WebUtil.DEBUG, String.format("setSrc - id %s, title %s, mimeType %s, isYoSsai %b, isAmtSsai %b, " +
333+
Log.i(WebUtil.DEBUG, String.format("setSrc - id %s, title %s, resumePosition %d, mimeType %s, isYoSsai %b, isAmtSsai %b, " +
326334
"isImaDai %b, adTag %s, midRoll %s, license %s, url %s",
327335
id,
328336
channelName == null && muxData != null && muxData.hasKey("videoTitle") ? muxData.getString("videoTitle") : channelName,
337+
resumePosition,
329338
mimeType,
330339
adProperties[1] != null,
331340
adProperties[2] != null,
@@ -360,6 +369,7 @@ public void setSrc(final ReactTVExoplayerView videoView, @Nullable ReadableMap s
360369
apsTestMode,
361370
Watermark.fromMap(metadata),
362371
limitedSeekRange,
372+
resumePosition,
363373
shouldSaveSubtitleSelection,
364374
selectedSubtitleTrack,
365375
preferredAudioTracks,
@@ -687,42 +697,17 @@ public static Map<String, String> toStringMap(@Nullable ReadableMap readableMap)
687697
@Override
688698
public Map<String, Integer> getCommandsMap() {
689699
return MapBuilder.of(
690-
"seekToNow",
691-
COMMAND_SEEK_TO_NOW,
692-
"seekToTimestamp",
693-
COMMAND_SEEK_TO_TIMESTAMP,
694-
"seekToResumePosition",
695-
COMMAND_SEEK_TO_RESUME_POSITION,
696700
"seekToPosition",
697701
COMMAND_SEEK_TO_POSITION,
698702
"replaceAdTagParameters",
699-
COMMAND_REPLACE_AD_TAG_PARAMETERS,
700-
"limitSeekableRange",
701-
COMMAND_LIMIT_SEEKABLE_RANGE
703+
COMMAND_REPLACE_AD_TAG_PARAMETERS
702704
);
703705
}
704706

705707
@Override
706708
public void receiveCommand(final ReactTVExoplayerView root, int commandId, @Nullable ReadableArray args) {
707709
// This will be called whenever a command is sent from react-native.
708710
switch (commandId) {
709-
case COMMAND_SEEK_TO_NOW:
710-
Log.i(WebUtil.DEBUG, "resumeToNow");
711-
root.resumeTo(C.TIME_UNSET);
712-
break;
713-
case COMMAND_SEEK_TO_TIMESTAMP:
714-
String timestamp = args.getString(0);
715-
Log.i(WebUtil.DEBUG, "resumeToTimeStamp " + timestamp);
716-
long positionMs = root.parseTimestamp(timestamp);
717-
if (positionMs != ResumePositionHandler.RESUME_UNSET) {
718-
root.resumeTo(positionMs);
719-
}
720-
break;
721-
case COMMAND_SEEK_TO_RESUME_POSITION:
722-
long resumeMs = args.getInt(0) * 1000;
723-
Log.i(WebUtil.DEBUG, "resumeToPosition " + resumeMs);
724-
root.resumeTo(resumeMs);
725-
break;
726711
case COMMAND_SEEK_TO_POSITION:
727712
long seekToMs = args.getInt(0) * 1000;
728713
Log.i(WebUtil.DEBUG, "seekToPosition " + seekToMs);
@@ -731,9 +716,6 @@ public void receiveCommand(final ReactTVExoplayerView root, int commandId, @Null
731716
case COMMAND_REPLACE_AD_TAG_PARAMETERS:
732717
root.replaceAdTagParameters(args.getMap(0) != null ? args.getMap(0).toHashMap() : null);
733718
break;
734-
case COMMAND_LIMIT_SEEKABLE_RANGE:
735-
root.setLimitedSeekRange(generateRange(args.getMap(0)));
736-
break;
737719
}
738720
}
739721

ios/JSProps/Source.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct Source: SuperCodable {
3636
let dvrSeekForwardInterval: Int?
3737
let dvrSeekBackwardInterval: Int?
3838
var plugins: JSPlugins?
39+
let resumePosition: Int?
3940
}
4041

4142

ios/Video/NewPlayerView.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,6 @@ class NewPlayerView: UIView, JSInputProtocol {
177177
var jsProps = JSProps()
178178
var jsPlayerView: RNDReactNativeDiceVideo.JSPlayerView?
179179

180-
func seekToNow() {
181-
jsPlayerView?.seekNow()
182-
}
183-
184-
func seekToTimestamp(isoDate: String) {
185-
jsPlayerView?.seek(isoDate)
186-
}
187180

188181
//TODO: pass this value as part of source
189182
func seekToPosition(position: Double) {
@@ -234,24 +227,6 @@ class NewPlayerView: UIView, JSInputProtocol {
234227
self.jsProps.startAt = Dynamic(nil)
235228
}
236229

237-
//moved to source
238-
func setInitialSeek(position: Double) {
239-
jsProps.startAt.value = position
240-
}
241-
242-
//moved to source
243-
func setupLimitedSeekableRange(with range: Source.LimitedSeekableRange?) {
244-
let start = Date(timeIntervalSince1970InMilliseconds: range?.start)
245-
let end = Date(timeIntervalSince1970InMilliseconds: range?.end)
246-
247-
if let end = end, end > Date() {
248-
//avoid finishing playback when ongoing live program reaches its end
249-
jsPlayerView?.dorisGlue?.doris?.player.setLimitedSeekableRange(range: (start: start, end: nil))
250-
} else {
251-
jsPlayerView?.dorisGlue?.doris?.player.setLimitedSeekableRange(range: (start: start, end: end))
252-
}
253-
}
254-
255230
override func layoutSubviews() {
256231
super.layoutSubviews()
257232
if jsPlayerView == nil {

ios/Video/PlayerViewProxy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class PlayerViewProxy {
238238
config: jsConfig,
239239
imageUri: jsProps.metadata.value?.thumbnailUrl,
240240
thumbnailsPreview: sourceValue.thumbnailsPreview,
241-
resumePosition: jsProps.startAt.value,
241+
resumePosition: sourceValue.resumePosition.map { Double($0) },
242242
delay: nil,
243243
ads: sourceValue.ads,
244244
metadata: metadata,

ios/Video/RCTVideoManager.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ @interface RCT_EXTERN_MODULE(RCTVideoManager, RCTViewManager)
6464
RCT_EXPORT_VIEW_PROPERTY(onSubtitleTrackChanged, RCTBubblingEventBlock);
6565
RCT_EXPORT_VIEW_PROPERTY(onAudioTrackChanged, RCTBubblingEventBlock)
6666

67-
RCT_EXTERN_METHOD(seekToNow:(nonnull NSNumber *)node)
68-
RCT_EXTERN_METHOD(seekToTimestamp:(nonnull NSNumber *)node isoDate:(NSString *)isoDate)
6967
RCT_EXTERN_METHOD(seekToPosition:(nonnull NSNumber *)node position:(double)position)
7068
RCT_EXTERN_METHOD(replaceAdTagParameters:(nonnull NSNumber *)node payload:(NSDictionary)payload)
71-
RCT_EXTERN_METHOD(seekToResumePosition:(nonnull NSNumber *)node position:(double)position)
72-
RCT_EXTERN_METHOD(limitSeekableRange:(nonnull NSNumber *)node payload:(NSDictionary)payload)
7369

7470
@end

ios/Video/RCTVideoManager.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ class RCTVideoManager: RCTViewManager {
2020
return view
2121
}
2222

23-
//MARK: Differs (ios only)
24-
@objc public func seekToNow(_ node: NSNumber) {
25-
DispatchQueue.main.async {
26-
let component = self.bridge.uiManager.view(forReactTag: node) as? NewPlayerView
27-
component?.seekToNow()
28-
}
29-
}
30-
31-
//MARK: Differs (ios only)
32-
@objc public func seekToTimestamp(_ node: NSNumber, isoDate: String) {
33-
DispatchQueue.main.async {
34-
let component = self.bridge.uiManager.view(forReactTag: node) as? NewPlayerView
35-
component?.seekToTimestamp(isoDate: isoDate)
36-
}
37-
}
38-
3923
@objc public func seekToPosition(_ node: NSNumber, position: Double) {
4024
DispatchQueue.main.async {
4125
let component = self.bridge.uiManager.view(forReactTag: node) as? NewPlayerView
@@ -68,22 +52,6 @@ class RCTVideoManager: RCTViewManager {
6852
validUntil: endDate)
6953
}
7054
}
71-
72-
@objc public func seekToResumePosition(_ node: NSNumber, position: Double) {
73-
DispatchQueue.main.async {
74-
let component = self.bridge.uiManager.view(forReactTag: node) as? NewPlayerView
75-
component?.setInitialSeek(position: position)
76-
}
77-
}
78-
79-
@objc public func limitSeekableRange(_ node: NSNumber, payload: NSDictionary) {
80-
DispatchQueue.main.async {
81-
let component = self.bridge.uiManager.view(forReactTag: node) as? NewPlayerView
82-
if let limitedSeekbleRange = try? Source.LimitedSeekableRange(dict: payload) {
83-
component?.setupLimitedSeekableRange(with: limitedSeekbleRange)
84-
}
85-
}
86-
}
8755

8856
override static func requiresMainQueueSetup() -> Bool {
8957
return true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-video",
3-
"version": "7.10.16",
3+
"version": "7.10.17",
44
"dorisAndroidVersion": "3.14.8",
55
"messagingAndroidVersion": "1.1.0",
66
"description": "A <Video /> element for react-native",

0 commit comments

Comments
 (0)