Merge pull request #1016 from react-native-community/bugfix/progress-timer-ios-onend
Clear the progress timer on iOS when onEnd is reached
This commit is contained in:
commit
bed9997287
@ -124,6 +124,16 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
return (kCMTimeRangeZero);
|
return (kCMTimeRangeZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)addPlayerTimeObserver
|
||||||
|
{
|
||||||
|
const Float64 progressUpdateIntervalMS = _progressUpdateInterval / 1000;
|
||||||
|
// @see endScrubbing in AVPlayerDemoPlaybackViewController.m of https://developer.apple.com/library/ios/samplecode/AVPlayerDemo/Introduction/Intro.html
|
||||||
|
__weak RCTVideo *weakSelf = self;
|
||||||
|
_timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(progressUpdateIntervalMS, NSEC_PER_SEC)
|
||||||
|
queue:NULL
|
||||||
|
usingBlock:^(CMTime time) { [weakSelf sendProgressUpdate]; }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/* Cancels the previously registered time observer. */
|
/* Cancels the previously registered time observer. */
|
||||||
-(void)removePlayerTimeObserver
|
-(void)removePlayerTimeObserver
|
||||||
@ -289,13 +299,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
[_player addObserver:self forKeyPath:playbackRate options:0 context:nil];
|
[_player addObserver:self forKeyPath:playbackRate options:0 context:nil];
|
||||||
_playbackRateObserverRegistered = YES;
|
_playbackRateObserverRegistered = YES;
|
||||||
|
|
||||||
const Float64 progressUpdateIntervalMS = _progressUpdateInterval / 1000;
|
[self addPlayerTimeObserver];
|
||||||
// @see endScrubbing in AVPlayerDemoPlaybackViewController.m of https://developer.apple.com/library/ios/samplecode/AVPlayerDemo/Introduction/Intro.html
|
|
||||||
__weak RCTVideo *weakSelf = self;
|
|
||||||
_timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(progressUpdateIntervalMS, NSEC_PER_SEC)
|
|
||||||
queue:NULL
|
|
||||||
usingBlock:^(CMTime time) { [weakSelf sendProgressUpdate]; }
|
|
||||||
];
|
|
||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
//Perform on next run loop, otherwise onVideoLoadStart is nil
|
||||||
@ -488,6 +492,8 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
AVPlayerItem *item = [notification object];
|
AVPlayerItem *item = [notification object];
|
||||||
[item seekToTime:kCMTimeZero];
|
[item seekToTime:kCMTimeZero];
|
||||||
[self applyModifiers];
|
[self applyModifiers];
|
||||||
|
} else {
|
||||||
|
[self removePlayerTimeObserver];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,6 +573,9 @@ static NSString *const timedMetadata = @"timedMetadata";
|
|||||||
if (CMTimeCompare(current, cmSeekTime) != 0) {
|
if (CMTimeCompare(current, cmSeekTime) != 0) {
|
||||||
if (!wasPaused) [_player pause];
|
if (!wasPaused) [_player pause];
|
||||||
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
||||||
|
if (!_timeObserver) {
|
||||||
|
[self addPlayerTimeObserver];
|
||||||
|
}
|
||||||
if (!wasPaused) [_player play];
|
if (!wasPaused) [_player play];
|
||||||
if(self.onVideoSeek) {
|
if(self.onVideoSeek) {
|
||||||
self.onVideoSeek(@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
self.onVideoSeek(@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
||||||
|
Loading…
Reference in New Issue
Block a user