如何使用自定义 NSURLProtocol 播放带有 URL 的电影?

发布于 2024-10-06 17:04:30 字数 223 浏览 0 评论 0原文

如您所知,现在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

更新:我与 Apple 讨论了此事,目前无法将 MPMoviePlayerController 与 NSURLProtocol 子类一起使用!


Hej,

我不确定,但这是可能的。我目前正在做类似的事情,但还没有完全发挥作用。我发现 MPMoviePlayerController 与我的自定义 NSURLProtocol 子类交互,但考虑 NSURLRequest 的 HTTPHeaders 似乎很重要,因为它们定义了 MPMoviePlayerController 所需的字节范围。

如果你将它们转储到你的 NSURLProtocol 子类中,你会在开始时得到类似的两次:

2011-01-16 17:00:47.287 iPhoneApp[1177:5f03] Start loading from request: {
Range = "bytes=0-1";

}

所以我的猜测是,只要你能提供正确的范围并返回一个可以由 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:

2011-01-16 17:00:47.287 iPhoneApp[1177:5f03] Start loading from request: {
Range = "bytes=0-1";

}

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

著墨染雨君画夕 2024-10-13 17:04:30

解决方案是通过本地 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.

自由如风 2024-10-13 17:04:30

从 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.

入怼 2024-10-13 17:04:30
@property AVPlayerViewController *avPlayerVC;
@property NSData *yourDataSource

// initialise avPlayerVC
    NSURL *dummyURL     = [NSURL URLWithString:@"foobar://dummy.mov"];// a non-reachable URL will force the use of the resourceLoader
    AVURLAsset *asset   = [AVURLAsset assetWithURL:dummyURL];
    [asset.resourceLoader setDelegate:self queue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)];

    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];

    self.avPlayerVC.player = [AVPlayer playerWithPlayerItem:item];
    self.avPlayerVC.player.actionAtItemEnd  = AVPlayerActionAtItemEndNone;



// implement AVAssetResourceLoaderDelegate

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

    loadingRequest.contentInformationRequest.contentType    = (__bridge NSString *)kUTTypeQuickTimeMovie;
    loadingRequest.contentInformationRequest.contentLength  = self.yourDataSource.length;
    loadingRequest.contentInformationRequest.byteRangeAccessSupported   = YES;

    NSRange range = NSMakeRange((NSUInteger)loadingRequest.dataRequest.requestedOffset, loadingRequest.dataRequest.requestedLength);
    [loadingRequest.dataRequest respondWithData:[self.yourDataSource subdataWithRange:range]];

    [loadingRequest finishLoading];
    return YES;
}

请注意,使用虚拟 URL 强制 AVPlayer 使用 AVAssetResourceLoaderDelegate 方法,而不是直接访问 URL。

@property AVPlayerViewController *avPlayerVC;
@property NSData *yourDataSource

// initialise avPlayerVC
    NSURL *dummyURL     = [NSURL URLWithString:@"foobar://dummy.mov"];// a non-reachable URL will force the use of the resourceLoader
    AVURLAsset *asset   = [AVURLAsset assetWithURL:dummyURL];
    [asset.resourceLoader setDelegate:self queue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)];

    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];

    self.avPlayerVC.player = [AVPlayer playerWithPlayerItem:item];
    self.avPlayerVC.player.actionAtItemEnd  = AVPlayerActionAtItemEndNone;



// implement AVAssetResourceLoaderDelegate

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

    loadingRequest.contentInformationRequest.contentType    = (__bridge NSString *)kUTTypeQuickTimeMovie;
    loadingRequest.contentInformationRequest.contentLength  = self.yourDataSource.length;
    loadingRequest.contentInformationRequest.byteRangeAccessSupported   = YES;

    NSRange range = NSMakeRange((NSUInteger)loadingRequest.dataRequest.requestedOffset, loadingRequest.dataRequest.requestedLength);
    [loadingRequest.dataRequest respondWithData:[self.yourDataSource subdataWithRange:range]];

    [loadingRequest finishLoading];
    return YES;
}

Notice the use of a dummy URL to force AVPlayer to use the AVAssetResourceLoaderDelegate methods instead of accessing the URL directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文