Add custom header field in request of AVPlayer

前端 未结 6 1939
陌清茗
陌清茗 2020-11-29 00:21

Is it possible to send headers with an http request to an audio file when using AVPlayer? I need to be able to inspect the content of the header when received by the server

6条回答
  •  佛祖请我去吃肉
    2020-11-29 00:38

    You'll need to request the data yourself via a generic HTTP connection mechanism such as NSURLConnection. If the NSHTTPURLResponse's headers pass your test, then you should save it into the NSCachesDirectory and pass off the URL to this resource to the AVPlayer like so:

    NSData *data = //your downloaded data.
    NSString *filePath = //generate random path under NSCachesDirectory
    [data writeToFile:filePath atomically:YES];
    
    AVPlayer *player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:filePath]];
    //...
    

提交回复
热议问题