AVAssetResourceLoaderDelegate proxy method execution logic

Create player

  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];

Implement proxy methods

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

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

Notice

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@“kkkk”] options:nil]; The url used here needs to be an illegal URL, that is, the video or audio URL cannot be requested normally. Only in this way can AVPlayer
Video resources will be obtained through the proxy method

Guess you like

Origin blog.csdn.net/LIUXIAOXIAOBO/article/details/122606433