Reuse audio source in setClip on iOS

This commit is contained in:
Ryan Heise 2020-08-01 02:07:09 +10:00
parent 165790851e
commit ebc8584b97
3 changed files with 32 additions and 2 deletions

View File

@ -479,7 +479,26 @@
} }
} }
// Decode audio source // Decode audio source
_audioSource = [self decodeAudioSource:source]; if (_audioSource && [@"clipping" isEqualToString:source[@"type"]]) {
// Check if we're clipping an audio source that was previously loaded.
UriAudioSource *child = nil;
if ([_audioSource isKindOfClass:[ClippingAudioSource class]]) {
ClippingAudioSource *clipper = (ClippingAudioSource *)_audioSource;
child = clipper.audioSource;
} else if ([_audioSource isKindOfClass:[UriAudioSource class]]) {
child = (UriAudioSource *)_audioSource;
}
if (child) {
_audioSource = [[ClippingAudioSource alloc] initWithId:source[@"id"]
audioSource:child
start:source[@"start"]
end:source[@"end"]];
} else {
_audioSource = [self decodeAudioSource:source];
}
} else {
_audioSource = [self decodeAudioSource:source];
}
_indexedAudioSources = [[NSMutableArray alloc] init]; _indexedAudioSources = [[NSMutableArray alloc] init];
[_audioSource buildSequence:_indexedAudioSources treeIndex:0]; [_audioSource buildSequence:_indexedAudioSources treeIndex:0];
for (int i = 0; i < [_indexedAudioSources count]; i++) { for (int i = 0; i < [_indexedAudioSources count]; i++) {
@ -523,7 +542,12 @@
[_indexedAudioSources[i] attach:_player]; [_indexedAudioSources[i] attach:_player];
} }
// We send result after the playerItem is ready in observeValueForKeyPath. if (_player.currentItem.status == AVPlayerItemStatusReadyToPlay) {
_connectionResult(@([self getDuration]));
_connectionResult = nil;
} else {
// We send result after the playerItem is ready in observeValueForKeyPath.
}
} }
- (void)updateOrder { - (void)updateOrder {

View File

@ -19,6 +19,10 @@
return self; return self;
} }
- (UriAudioSource *)audioSource {
return _audioSource;
}
- (void)findById:(NSString *)sourceId matches:(NSMutableArray<AudioSource *> *)matches { - (void)findById:(NSString *)sourceId matches:(NSMutableArray<AudioSource *> *)matches {
[super findById:sourceId matches:matches]; [super findById:sourceId matches:matches];
[_audioSource findById:sourceId matches:matches]; [_audioSource findById:sourceId matches:matches];

View File

@ -4,6 +4,8 @@
@interface ClippingAudioSource : IndexedAudioSource @interface ClippingAudioSource : IndexedAudioSource
@property (readonly, nonatomic) UriAudioSource* audioSource;
- (instancetype)initWithId:(NSString *)sid audioSource:(UriAudioSource *)audioSource start:(NSNumber *)start end:(NSNumber *)end; - (instancetype)initWithId:(NSString *)sid audioSource:(UriAudioSource *)audioSource start:(NSNumber *)start end:(NSNumber *)end;
@end @end