ios - iOS 6 上的 AVAssetResourceLoaderDelegate 协议(protocol)
<p><p>我已经设法让 <code>AVPlayer</code> 与 <code>AVAssetResourceLoaderDelegate</code> 一起在 <code>iOS 7</code> 上播放 m4a 文件,但我无法在 <code>iOS 上执行此操作6</code>.</p>
<p></p>
<pre><code>- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
</code></pre>
<p>委托(delegate)方法被以下请求调用:</p>
<pre><code>2014-05-12 15:14:58.798 AVPlayer-Delegate Requested data: {
Range = "bytes=0-1";
"X-Playback-Session-Id" = "5B64BE4E-442A-4A37-9263-04D22CDBCB28";
}
</code></pre>
<p>我按要求返回了前两个字节,但委托(delegate)方法不再被调用。我试图在传递的响应对象中提供各种 header ,但没有帮助。</p>
<p>这是我的实现:</p>
<pre><code>- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
{
NSLog(@"Requested data: %@",
loadingRequest.request.allHTTPHeaderFields);
NSDictionary *headers = @{@"Content-Type": @"audio/x-m4a",
@"Accept-Ranges" : @"bytes",
@"Content-Length" : ,
@"Content-Range" : ,
@"X-Playback-Session-Id" : loadingRequest.request.allHTTPHeaderFields[@"X-Playback-Session-Id"],
@"ETag" : @"TAG"};
NSHTTPURLResponse *response = [ initWithURL:loadingRequest.request.URL statusCode:206 HTTPVersion:@"HTTP/1.1" headerFields:headers];
//NSURLResponse *response = [ initWithURL:loadingRequest.request.URL MIMEType:@"audio/m4a" expectedContentLength:self.fileData.length textEncodingName:@"UTF-8"];
NSData *requestedData = ;
;
return YES;
}
</code></pre>
<p>如果能提供任何帮助,我将不胜感激。</p>
<p>谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>AVAssetResourceLoaderDelegate 在 IOS 6 和 IOS 7 上的工作方式不同。参见 <a href="https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html" rel="noreferrer noopener nofollow">What's New in IOS 7.0</a> </p>
<blockquote>
<p>The AVAssetResourceLoaderDelegate protocol now supports loading of
arbitrary ranges of bytes from a media resource.</p>
</blockquote>
<p>IOS7 之前的标准解决方法是使用本地 HTTP 服务器。参见示例 <a href="https://stackoverflow.com/a/21225985" rel="noreferrer noopener nofollow">https://stackoverflow.com/a/21225985</a> </p></p>
<p style="font-size: 20px;">关于ios - iOS 6 上的 AVAssetResourceLoaderDelegate 协议(protocol),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23612094/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23612094/
</a>
</p>
页:
[1]