-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: implement startPosition #3355
Changes from all commits
d43a4c8
9e81200
41b8e32
7a1d04a
9e99e38
23fb63e
6bb5816
0369f8c
c0f3d3d
4fb8b03
dcf1434
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH | |
private var _filterEnabled:Bool = false | ||
private var _presentingViewController:UIViewController? | ||
private var _pictureInPictureEnabled = false | ||
private var _startPosition:Float64 = -1 | ||
|
||
/* IMA Ads */ | ||
private var _adTagUrl:String? | ||
|
@@ -251,8 +252,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH | |
} | ||
|
||
var currentTime = _player?.currentTime() | ||
if (currentTime != nil && _source?.startTime != nil) { | ||
currentTime = CMTimeSubtract(currentTime!, CMTimeMake(value: _source?.startTime ?? 0, timescale: 1000)) | ||
if (currentTime != nil && _source?.cropStart != nil) { | ||
currentTime = CMTimeSubtract(currentTime!, CMTimeMake(value: _source?.cropStart ?? 0, timescale: 1000)) | ||
} | ||
let currentPlaybackTime = _player?.currentItem?.currentDate() | ||
let duration = CMTimeGetSeconds(playerDuration) | ||
|
@@ -316,6 +317,10 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH | |
throw NSError(domain: "", code: 0, userInfo: nil) | ||
} | ||
|
||
if let startPosition = self._source?.startPosition { | ||
self._startPosition = Float64(startPosition) / 1000 | ||
} | ||
|
||
#if USE_VIDEO_CACHING | ||
if self._videoCache.shouldCache(source:source, textTracks:self._textTracks) { | ||
return self._videoCache.playerItemForSourceUsingCache(uri: source.uri, assetOptions:assetOptions) | ||
|
@@ -341,7 +346,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH | |
self._playerItem = playerItem | ||
self._playerObserver.playerItem = self._playerItem | ||
self.setPreferredForwardBufferDuration(self._preferredForwardBufferDuration) | ||
self.setPlaybackRange(playerItem, withVideoStart: self._source?.startTime, withVideoEnd: self._source?.endTime) | ||
self.setPlaybackRange(playerItem, withVideoStart: self._source?.cropStart, withVideoEnd: self._source?.cropEnd) | ||
self.setFilter(self._filterName) | ||
if let maxBitRate = self._maxBitRate { | ||
self._playerItem?.preferredPeakBitRate = Double(maxBitRate) | ||
|
@@ -601,6 +606,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH | |
_pendingSeek = false | ||
} | ||
|
||
|
||
@objc | ||
func setRate(_ rate:Float) { | ||
_rate = rate | ||
|
@@ -1177,6 +1183,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH | |
_pendingSeek = false | ||
} | ||
|
||
if _startPosition >= 0 { | ||
setSeek([ | ||
"time": NSNumber(value: _startPosition), | ||
"tolerance": NSNumber(value: 100) | ||
]) | ||
_startPosition = -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it really need to force _startPosition to -1 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was assuming that the playback would work fine, then an error would occur, and then it would work again. When the source is unchanged and the lifecycle is as follows,
I forced it to But I'm not very experienced with iOS, and I don't know much about it. If my assumptions are wrong, feel free to let me know and I'll correct above code. |
||
} | ||
|
||
if _videoLoadStarted { | ||
let audioTracks = RCTVideoUtils.getAudioTrackInfo(_player) | ||
let textTracks = RCTVideoUtils.getTextTrackInfo(_player).map(\.json) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch !