Queue seek request until ready to play on iOS.
This commit is contained in:
parent
5d0ce955f4
commit
037795674f
|
@ -672,6 +672,7 @@
|
|||
if ([statusNumber isKindOfClass:[NSNumber class]]) {
|
||||
status = statusNumber.intValue;
|
||||
}
|
||||
[playerItem.audioSource onStatusChanged:status];
|
||||
switch (status) {
|
||||
case AVPlayerItemStatusReadyToPlay: {
|
||||
if (playerItem != _player.currentItem) return;
|
||||
|
|
|
@ -56,6 +56,8 @@
|
|||
if (!completionHandler || (self.playerItem.status == AVPlayerItemStatusReadyToPlay)) {
|
||||
CMTime absPosition = CMTimeAdd(_start, position);
|
||||
[_audioSource.playerItem seekToTime:absPosition toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
|
||||
} else {
|
||||
[super seek:position completionHandler:completionHandler];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,31 @@
|
|||
|
||||
@implementation IndexedAudioSource {
|
||||
BOOL _isAttached;
|
||||
CMTime _queuedSeekPos;
|
||||
void (^_queuedSeekCompletionHandler)(BOOL);
|
||||
}
|
||||
|
||||
- (instancetype)initWithId:(NSString *)sid {
|
||||
self = [super init];
|
||||
NSAssert(self, @"super init cannot be nil");
|
||||
_isAttached = NO;
|
||||
_queuedSeekPos = kCMTimeInvalid;
|
||||
_queuedSeekCompletionHandler = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)onStatusChanged:(AVPlayerItemStatus)status {
|
||||
if (status == AVPlayerItemStatusReadyToPlay) {
|
||||
// This handles a pending seek during a load.
|
||||
// TODO: Test seeking during a seek.
|
||||
if (_queuedSeekCompletionHandler) {
|
||||
[self seek:_queuedSeekPos completionHandler:_queuedSeekCompletionHandler];
|
||||
_queuedSeekPos = kCMTimeInvalid;
|
||||
_queuedSeekCompletionHandler = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (IndexedPlayerItem *)playerItem {
|
||||
return nil;
|
||||
}
|
||||
|
@ -48,6 +64,10 @@
|
|||
}
|
||||
|
||||
- (void)seek:(CMTime)position completionHandler:(void (^)(BOOL))completionHandler {
|
||||
if (completionHandler && (self.playerItem.status != AVPlayerItemStatusReadyToPlay)) {
|
||||
_queuedSeekPos = position;
|
||||
_queuedSeekCompletionHandler = completionHandler;
|
||||
}
|
||||
}
|
||||
|
||||
- (CMTime)duration {
|
||||
|
|
|
@ -56,6 +56,8 @@
|
|||
position = CMTimeAdd(position, range.start);
|
||||
}
|
||||
[_playerItem seekToTime:position toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
|
||||
} else {
|
||||
[super seek:position completionHandler:completionHandler];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
@property (readonly, nonatomic) CMTime bufferedPosition;
|
||||
@property (readonly, nonatomic) BOOL isAttached;
|
||||
|
||||
- (void)onStatusChanged:(AVPlayerItemStatus)status;
|
||||
- (void)attach:(AVQueuePlayer *)player;
|
||||
- (void)play:(AVQueuePlayer *)player;
|
||||
- (void)pause:(AVQueuePlayer *)player;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
@property (readonly, nonatomic) CMTime bufferedPosition;
|
||||
@property (readonly, nonatomic) BOOL isAttached;
|
||||
|
||||
- (void)onStatusChanged:(AVPlayerItemStatus)status;
|
||||
- (void)attach:(AVQueuePlayer *)player;
|
||||
- (void)play:(AVQueuePlayer *)player;
|
||||
- (void)pause:(AVQueuePlayer *)player;
|
||||
|
|
Loading…
Reference in New Issue