Skip to content

Commit

Permalink
Merge pull request #800 from tablexi/allow-progress-update-interval-t…
Browse files Browse the repository at this point in the history
…o-work-on-ios

Allow setting progressUpdateInterval to work on iOS
  • Loading branch information
cobarx committed May 29, 2018
2 parents f0de6bb + fd8ebbd commit 6c139a7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions ios/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,16 @@ - (CMTimeRange)playerItemSeekableTimeRange
return (kCMTimeRangeZero);
}

- (void)addPlayerTimeObserver
-(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]; }
];
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. */
Expand Down Expand Up @@ -738,6 +739,11 @@ - (void)setControls:(BOOL)controls
- (void)setProgressUpdateInterval:(float)progressUpdateInterval
{
_progressUpdateInterval = progressUpdateInterval;

if (_timeObserver) {
[self removePlayerTimeObserver];
[self addPlayerTimeObserver];
}
}

- (void)removePlayerLayer
Expand Down

0 comments on commit 6c139a7

Please sign in to comment.