Update UriAudioSource.m (#181)

This commit is contained in:
snaeji 2020-09-13 11:08:56 +00:00 committed by GitHub
parent c48bf4c2b0
commit 65912ec4e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 3 deletions

View File

@ -50,19 +50,36 @@
- (void)seek:(CMTime)position completionHandler:(void (^)(BOOL))completionHandler {
if (!completionHandler || (_playerItem.status == AVPlayerItemStatusReadyToPlay)) {
[_playerItem seekToTime:position toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
CMTimeRange seekableRange = [_playerItem.seekableTimeRanges.lastObject CMTimeRangeValue];
CMTime relativePosition = CMTimeAdd(position, seekableRange.start);
[_playerItem seekToTime:relativePosition toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
}
}
- (CMTime)duration {
NSValue *seekableRange = _playerItem.seekableTimeRanges.lastObject;
if (seekableRange) {
CMTimeRange seekableDuration = [seekableRange CMTimeRangeValue];;
return seekableDuration.duration;
}
else {
return _playerItem.duration;
}
return kCMTimeInvalid;
}
- (void)setDuration:(CMTime)duration {
}
- (CMTime)position {
NSValue *seekableRange = _playerItem.seekableTimeRanges.lastObject;
if (seekableRange) {
CMTimeRange range = [seekableRange CMTimeRangeValue];
return CMTimeSubtract(_playerItem.currentTime, range.start);
} else {
return _playerItem.currentTime;
}
}
- (CMTime)bufferedPosition {