Thanks to these two posts, I solve this problem while creating AVPLayerItem. Play AVQueuePlayer without tearing and freezing. AVPlayer "freezes" application at the beginning of audio stream buffering.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:urlString] options:@{AVURLAssetPreferPreciseDurationAndTimingKey : @(YES)}]; NSArray *keys = @[@"playable", @"tracks",@"duration" ]; [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^() { for (NSString *thisKey in keys) { NSError *error = nil; AVKeyValueStatus keyStatus = [asset statusOfValueForKey:thisKey error:&error]; if (keyStatus == AVKeyValueStatusFailed) { return ; } } AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:asset]; dispatch_async(dispatch_get_main_queue(), ^ { [item addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; [player insertItem:item afterItem:nil]; }); }]; });
But with the stream from Soundcloud ( https://api.soundcloud.com/tracks/146924238/stream?client_id=76395c48f97de903ff44861e230116bd ), after the status of the item is ready to play (AVPlayerStatusReadyToPlay), AVQueueplayer basically continue to do something freezing "user interface (the track continues to play in the background stream).
I noticed that this problem is more important when the network is low. Then I concluded that this freeze exists when an element is buffering a stream.
Does anyone have a solution or a trick?
source share