AVAssetResourceLoaderDelegate methods not working on device

后端 未结 3 1143
予麋鹿
予麋鹿 2020-12-10 19:32

I have been working on a simple AVPlayer to play encrypted HLS media.

I am using the AVAssetResourceLoaderDelegate to handle t

相关标签:
3条回答
  • 2020-12-10 20:03

    If you take a look on Apple example code where they show bipbop.m3u8 HLS playback you will see that they are using masks for real http requests: "http:/host/bipbop.m3u8" => "custom_scheme:/host/bipbop.m3u8" Same trick should be made with playlist subresources.

    Otherwise avplayer ignores AVAssetResourceLoaderDelegate and load data directly.

    You need to implement some kind of mapping:

    NSString* videoUrl = @"fake_scheme://host/video.m3u8";
    NSURL *streamURL = [NSURL URLWithString:videoUrl];
    
    0 讨论(0)
  • 2020-12-10 20:04

    In your delegate shouldWaitForLoadingOfRequestedResource change the URL scheme back to http:

    NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:loadingRequest.request.URL resolvingAgainstBaseURL:NO];
        urlComponents.scheme = @"http";
    NSMutableURLRequest *mutableLoadingRequest = [loadingRequest.request mutableCopy];
    [mutableLoadingRequest setURL:urlComponents.URL];
    
    0 讨论(0)
  • 2020-12-10 20:07

    As I mentioned in the other thread as well, AVAssetResourceLoaderDelegate works only when we use a "Non Standard/Non Reserved" url scheme. HTTP, HTTPS etc are considered reserved URL schemes and iOS will not make a delegate call if the URL has one of those schemes. What I ended up doing was using my_own_http for the http urls and my_own_https for the https urls. It works well after I made that change. As you know this makes your playlist unusable on other deices.

    0 讨论(0)
提交回复
热议问题