如何使用自定义 NSURLProtocol 播放带有 URL 的电影?
如您所知,现在使用 MPMoviePlayerController 对象播放电影
[[MPMoviePlayerController alloc] initWithContentURL: aURL];
,我想实现一个自定义 NSURLProtocol,在其中我将解密已通过 AlgorithmDES 加密的电影源。 有这种可能吗?感谢您提供任何想法。需要您的帮助~
As you know,play a movie with MPMoviePlayerController object using
[[MPMoviePlayerController alloc] initWithContentURL: aURL];
now ,i want to achieve a custom NSURLProtocol in which i will decrypt a movie source that had be encrypt by AlgorithmDES.
Is that possibility? thanks for giving any ideas.need you help~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更新:我与 Apple 讨论了此事,目前无法将 MPMoviePlayerController 与 NSURLProtocol 子类一起使用!
Hej,
我不确定,但这是可能的。我目前正在做类似的事情,但还没有完全发挥作用。我发现 MPMoviePlayerController 与我的自定义 NSURLProtocol 子类交互,但考虑 NSURLRequest 的 HTTPHeaders 似乎很重要,因为它们定义了 MPMoviePlayerController 所需的字节范围。
如果你将它们转储到你的 NSURLProtocol 子类中,你会在开始时得到类似的两次:
}
所以我的猜测是,只要你能提供正确的范围并返回一个可以由 MPMoviePlayerController 播放的 mp4 文件,那应该是可能的!
编辑:这是一个有趣的链接:保护 iPhone 和 iPad 应用程序中的资源
UPDATE: I spoke to Apple about this and it's not possible to use MPMoviePlayerController with a NSURLProtocol subclass at the moment!
Hej,
I am not sure but it could be possible. I am currently working on something similar but haven't got it fully working. What I have found out is that MPMoviePlayerController interacts with my custom NSURLProtocol subclass BUT it seems to be important to take the HTTPHeaders of the NSURLRequest into account because they define a range of bytes the MPMoviePlayerController needs.
If you dump them in your NSURLProtocol subclass you will get something like this twice for the start:
}
So my GUESS is that as long as you can provide the correct range and return a mp4 file that can be played by the MPMoviePlayerController it should be possible!
EDIT: Here is a interesting link: Protecting resources in iPhone and iPad apps
解决方案是通过本地 HTTP 服务器代理请求。我已经使用 CocoaHTTPServer 完成了此操作。
查看
HTTPAsyncFileResponse
示例。The solution is to proxy requests through a local HTTP server. I have accomplished this using CocoaHTTPServer.
Look at the
HTTPAsyncFileResponse
example.从 iOS 7 开始,还有一种解决方案。您可以将 AVAssetResourceLoaderDelegate 用于 AVAssetResourceLoader。但这仅适用于 AVPlayer。
苹果有一个名为 AVARLDelegateDemo 的演示项目,看一下它,您应该会找到您需要的内容。 (我认为链接到它不是一个好主意,所以只需在developer.apple.com上的开发人员库中搜索它)然后使用任何自定义URL方案(无需声明NSURLProtocol)并在AVAssetResourceLoaderDelegate中处理该URL方案。
如果有很大兴趣,我可以提供概念证明要点。
There is one more solution as of iOS 7. You can use a AVAssetResourceLoaderDelegate for AVAssetResourceLoader. But this will only work with AVPlayer then.
There is a demo project by apple called AVARLDelegateDemo have a look at it and you should find what you need. (I think linking to it isn't a good idea, so just search for it in the Developer Library on developer.apple.com) Then use any custom URL scheme (without declaring a NSURLProtocol) and handle that URL scheme in the AVAssetResourceLoaderDelegate.
If there is a huge interest I could provide a proof of concept gist.
请注意,使用虚拟 URL 强制
AVPlayer
使用AVAssetResourceLoaderDelegate
方法,而不是直接访问 URL。Notice the use of a dummy URL to force
AVPlayer
to use theAVAssetResourceLoaderDelegate
methods instead of accessing the URL directly.