我設法得到AVPlayer
與AVAssetResourceLoaderDelegate
合作播放iOS 7
上的m4a文件,但我無法在iOS 6
上播放。iOS 6上的AVAssetResourceLoaderDelegate協議
的
- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
委託方法獲取調用具有以下要求:
2014-05-12 15:14:58.798 AVPlayer-Delegate[661:1103] Requested data: {
Range = "bytes=0-1";
"X-Playback-Session-Id" = "5B64BE4E-442A-4A37-9263-04D22CDBCB28";
}
我回國前兩個字節的要求,但委託方法永遠不會再次調用。我試圖在我傳遞的響應對象中提供各種標題,但它沒有幫助。
這是我實現:
- (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" : [NSString stringWithFormat:@"%d", 2],
@"Content-Range" : [NSString stringWithFormat:@"bytes 0-1/%d", self.fileData.length],
@"X-Playback-Session-Id" : loadingRequest.request.allHTTPHeaderFields[@"X-Playback-Session-Id"],
@"ETag" : @"TAG"};
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:loadingRequest.request.URL statusCode:206 HTTPVersion:@"HTTP/1.1" headerFields:headers];
//NSURLResponse *response = [[NSURLResponse alloc] initWithURL:loadingRequest.request.URL MIMEType:@"audio/m4a" expectedContentLength:self.fileData.length textEncodingName:@"UTF-8"];
NSData *requestedData = [self.fileData subdataWithRange:NSMakeRange(0, 2)];
[loadingRequest finishLoadingWithResponse:response data:requestedData redirect:nil];
return YES;
}
我真的很感激它的任何幫助。
謝謝。
你有沒有找到解決這個問題?我在iOS 7設備上看到了相同的行爲(僅請求前兩個字節)。在前兩個字節的初始請求後沒有請求。 – Alexander