AVAssetResourceLoaderDelegate 代理方法执行逻辑

创建播放器

  AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@"kkkk"] options:nil];
    [asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
     _player = [AVPlayer playerWithPlayerItem:_playerItem];

实现代理方法

#pragma mark - AVAssetResourceLoaderDelegate
- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader 
{
.....
    return YES;
}

- (void)resourceLoader:(AVAssetResourceLoader *)resourceLoader didCancelLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest {
 ....
}

注意

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@“kkkk”] options:nil]; 这里使用的url 需要是不合规的URL,就是无法正常请求到视频或者音频的URL,只有这样,AVPlayer 才会通过代理方法来获取
视频资源

你可能感兴趣的:(音视频,ios,objective-c,音视频)