AVAssetResourceLoader支持的AVURLAsset播放仅通过AirPlay失败 [英] AVAssetResourceLoader backed AVURLAsset playback fails only via AirPlay

查看:318
本文介绍了AVAssetResourceLoader支持的AVURLAsset播放仅通过AirPlay失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于与我的问题无关的原因,我必须使用自定义的AVAssetResourceLoader来实现AVPlayer播放AVURLAssets的操作.总的来说,我的实现效果很好,但是当尝试通过AirPlay进行外部播放(不是镜像)时:

For reasons irrelevant to my question I have to implement an AVPlayer playing back AVURLAssets using a custom AVAssetResourceLoader. In general my implementation works well, but when attempting external playback via AirPlay (not mirroring):

 self.player.allowsExternalPlayback = YES;
 self.player.usesExternalPlaybackWhileExternalScreenIsActive = YES;

播放失败,并在AppleTV上显示错误消息,并通过AVPlayerItemFailedToPlayToEndTimeNotification发布错误消息.

The playback fails with an error message on the AppleTV and an error message posted via AVPlayerItemFailedToPlayToEndTimeNotification.

我可以使用简单的AVAssetResourceLoader实现来重现相同的问题,该实现只需分发请求的本地媒体文件数据(包含在App Bundle中)即可.这是我的实现:

I am able to reproduce the same issue with a trivial AVAssetResourceLoader implementation which simply hands out the requested data of a local media file (included in the App Bundle). Here is my implementation:

- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest; {

AVAssetResourceLoadingDataRequest *dataRequest = loadingRequest.dataRequest;
AVAssetResourceLoadingContentInformationRequest *contentRequest = loadingRequest.contentInformationRequest;

NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"localfile" withExtension:@"mov"];

if (contentRequest)
{
    NSString *extension = [fileURL pathExtension];
    NSString *contentTypeString = (NSString*)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,(CFStringRef)extension,NULL);

    contentRequest.contentType = contentTypeString;
    contentRequest.contentLength = [[[NSFileManager defaultManager] attributesOfItemAtPath:[fileURL path] error:nil] fileSize];
    contentRequest.byteRangeAccessSupported = YES;
}

if (dataRequest)
{

    NSInteger length = [dataRequest requestedLength];
    if (length>1024*1024*20)
    {
        // limiting to 20MB here because iOS sometimes requests the whole file which would not fit in memory
        length = 1024*1024*20;
    }

    NSFileHandle *fh = [NSFileHandle fileHandleForReadingFromURL:fileURL error:nil];
    [fh seekToFileOffset:[dataRequest requestedOffset]];
    NSData *fileData = [fh readDataOfLength:length];
    [dataRequest respondWithData:fileData];
    [fh closeFile];
}

[loadingRequest finishLoading];

return YES;}

此代码可直接在设备上正常播放.如果启用了AirPlay,则资源加载器将被调用约4-5次内容和数据请求,并请求该项目的前8kb.回调然后停止,最终我在Apple TV和一些AVPlayerItemFailedToPlayToEndTimeNotifications上收到错误消息.第一个通知包含不支持的媒体"错误.

This code plays back fine on the device directly. If AirPlay is enabled, the resourceloader is called with content and data requests about 4-5 times, requesting the first 8kb of the item. The callbacks then stop and eventually I get a error message on the Apple TV and a few AVPlayerItemFailedToPlayToEndTimeNotifications. The first notification contains a "media not supported" error.

(通过将普通媒体文件项添加到AVPlayer来播放同一媒体,也可以通过AirPlay正常播放).

(Playing the same piece of media by adding it to the AVPlayer as a normal file based item plays fine via AirPlay as well).

任何输入将不胜感激,谢谢!

Any input would be much appreciated, thanks!

推荐答案

我现在已经收到苹果公司(通过TSI)对此问题的答复. 使用自定义资源加载器时,不支持Video AirPlay.

I have now received a response from Apple (via a TSI) to this question. Video AirPlay is not supported when using a custom resource loader.

这篇关于AVAssetResourceLoader支持的AVURLAsset播放仅通过AirPlay失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆