AVAssetResourceLoaderDelegate methods not working on the device

I worked on an easy AVPlayerto play encrypted media HLS.

I use AVAssetResourceLoaderDelegateto process the key extraction process so that the encrypted medium can play with a valid key.

The program works fine on the simulator, but it does not work on the device at all .

Here are the codes:

- (void) playUrlByAVPlayer:(NSString *) videoUrl
{
    NSURL *streamURL = [NSURL URLWithString:videoUrl];

    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:streamURL options:nil];

    [asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];

    self.playerItem = [AVPlayerItem playerItemWithAsset:asset];                           
    self.player = [AVPlayer playerWithPlayerItem:self.playerItem];

    self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    [self.playerLayer setFrame:self.view.frame];
    [self.view.layer addSublayer:self.playerLayer];

    [self.player play];
}

After some debugging, I realized that the delegate method was shouldWaitForLoadingOfRequestedResourcenever called on the device.

I read other relevant questions:

AVAssetResourceLoaderDelegate will not be called

AVAssetResourceLoaderDelegate - Request only the first two bytes?

I tried to include all of the codes in the unit dispatch_async, dispatch_get_main_queuebut will not be able to solve my problem.

.

?

+4
3

Apple, HLS bipbop.m3u8, , HTTP-: "http:/host/bipbop.m3u8" = > "custom_scheme:/host/bipbop.m3u8" .

avplayer AVAssetResourceLoaderDelegate .

- :

NSString* videoUrl = @"fake_scheme://host/video.m3u8";
NSURL *streamURL = [NSURL URLWithString:videoUrl];
+5

, AVAssetResourceLoaderDelegate , / URL-. HTTP, HTTPS .. URL-, iOS -, URL- . my_own_http http- my_own_https URL- https. , . , .

+3

shouldWaitForLoadingOfRequestedResource URL- http:

NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:loadingRequest.request.URL resolvingAgainstBaseURL:NO];
    urlComponents.scheme = @"http";
NSMutableURLRequest *mutableLoadingRequest = [loadingRequest.request mutableCopy];
[mutableLoadingRequest setURL:urlComponents.URL];
+1

All Articles