AVPlayer “freezes” the app at the start of buffering an audio stream

后端 未结 3 1378
灰色年华
灰色年华 2020-12-12 12:52

I am using a subclass of AVQueuePlayer and when I add new AVPlayerItem with a streaming URL the app freezes for about a second or two. By freezing

3条回答
  •  無奈伤痛
    2020-12-12 13:54

    Don't use playerItemWithURL it's sync. When you receive the response with the url try this:

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
    NSArray *keys = @[@"playable"];
    
    [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^() {
        [self.player insertItem:[AVPlayerItem playerItemWithAsset:asset] afterItem:nil];
    }];
    

提交回复
热议问题