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]]) {
|
if ([statusNumber isKindOfClass:[NSNumber class]]) {
|
||||||
status = statusNumber.intValue;
|
status = statusNumber.intValue;
|
||||||
}
|
}
|
||||||
|
[playerItem.audioSource onStatusChanged:status];
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case AVPlayerItemStatusReadyToPlay: {
|
case AVPlayerItemStatusReadyToPlay: {
|
||||||
if (playerItem != _player.currentItem) return;
|
if (playerItem != _player.currentItem) return;
|
||||||
|
|
|
@ -56,6 +56,8 @@
|
||||||
if (!completionHandler || (self.playerItem.status == AVPlayerItemStatusReadyToPlay)) {
|
if (!completionHandler || (self.playerItem.status == AVPlayerItemStatusReadyToPlay)) {
|
||||||
CMTime absPosition = CMTimeAdd(_start, position);
|
CMTime absPosition = CMTimeAdd(_start, position);
|
||||||
[_audioSource.playerItem seekToTime:absPosition toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
|
[_audioSource.playerItem seekToTime:absPosition toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
|
||||||
|
} else {
|
||||||
|
[super seek:position completionHandler:completionHandler];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,31 @@
|
||||||
|
|
||||||
@implementation IndexedAudioSource {
|
@implementation IndexedAudioSource {
|
||||||
BOOL _isAttached;
|
BOOL _isAttached;
|
||||||
|
CMTime _queuedSeekPos;
|
||||||
|
void (^_queuedSeekCompletionHandler)(BOOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithId:(NSString *)sid {
|
- (instancetype)initWithId:(NSString *)sid {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
NSAssert(self, @"super init cannot be nil");
|
NSAssert(self, @"super init cannot be nil");
|
||||||
_isAttached = NO;
|
_isAttached = NO;
|
||||||
|
_queuedSeekPos = kCMTimeInvalid;
|
||||||
|
_queuedSeekCompletionHandler = nil;
|
||||||
return self;
|
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 {
|
- (IndexedPlayerItem *)playerItem {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -48,6 +64,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seek:(CMTime)position completionHandler:(void (^)(BOOL))completionHandler {
|
- (void)seek:(CMTime)position completionHandler:(void (^)(BOOL))completionHandler {
|
||||||
|
if (completionHandler && (self.playerItem.status != AVPlayerItemStatusReadyToPlay)) {
|
||||||
|
_queuedSeekPos = position;
|
||||||
|
_queuedSeekCompletionHandler = completionHandler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CMTime)duration {
|
- (CMTime)duration {
|
||||||
|
|
|
@ -56,6 +56,8 @@
|
||||||
position = CMTimeAdd(position, range.start);
|
position = CMTimeAdd(position, range.start);
|
||||||
}
|
}
|
||||||
[_playerItem seekToTime:position toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
|
[_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) CMTime bufferedPosition;
|
||||||
@property (readonly, nonatomic) BOOL isAttached;
|
@property (readonly, nonatomic) BOOL isAttached;
|
||||||
|
|
||||||
|
- (void)onStatusChanged:(AVPlayerItemStatus)status;
|
||||||
- (void)attach:(AVQueuePlayer *)player;
|
- (void)attach:(AVQueuePlayer *)player;
|
||||||
- (void)play:(AVQueuePlayer *)player;
|
- (void)play:(AVQueuePlayer *)player;
|
||||||
- (void)pause:(AVQueuePlayer *)player;
|
- (void)pause:(AVQueuePlayer *)player;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
@property (readonly, nonatomic) CMTime bufferedPosition;
|
@property (readonly, nonatomic) CMTime bufferedPosition;
|
||||||
@property (readonly, nonatomic) BOOL isAttached;
|
@property (readonly, nonatomic) BOOL isAttached;
|
||||||
|
|
||||||
|
- (void)onStatusChanged:(AVPlayerItemStatus)status;
|
||||||
- (void)attach:(AVQueuePlayer *)player;
|
- (void)attach:(AVQueuePlayer *)player;
|
||||||
- (void)play:(AVQueuePlayer *)player;
|
- (void)play:(AVQueuePlayer *)player;
|
||||||
- (void)pause:(AVQueuePlayer *)player;
|
- (void)pause:(AVQueuePlayer *)player;
|
||||||
|
|
Loading…
Reference in New Issue