gpt4 book ai didi

ios - 如何使用 AVAssetResourceLoader?

转载 作者:可可西里 更新时间:2023-11-01 03:30:06 31 4
gpt4 key购买 nike

文档中提到了 AVURLAsset.resourceLoader:

During loading, the resource loader object may be asked to assist in the loading of a resource. For example, a resource that requires decryption might result in the resource loader being asked to provide the appropriate decryption keys. You can assign a delegate object to the resource loader object and use your delegate to intercept these requests and provide an appropriate response.

所以我想在我的代码中做的是:

NSURL* url = ...;
_asset = [[AVURLAsset alloc] initWithURL:url options:nil];

AVAssetResourceLoader* loader = _asset.resourceLoader;
[loader setDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];

_playerItem = [AVPlayerItem playerItemWithAsset:_asset];
_player = [AVPlayer playerWithPlayerItem:_playerItem];

// ... setting up the player layer

[_player play];

而且在我的类(class)中,我将 AVAssetResourceLoaderDelegate 添加到 @interface 中并实现了方法:

- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
{
NSLog(@"YES");
return YES;
}

无论传递什么 URL,都不会调用此方法。如果 URL 是通过 HTTP 或使用我自定义注册的 NSURLProtocol 的有效媒体,则无关紧要。

resourceLoader 应该什么时候调用它的委托(delegate)?

最佳答案

您应该尝试使用自定义 URL 方案,例如:使用 my_custom_scheme://myserver.com/listen.m3u 而不是 http://myserver.com/listen.m3u 。默认情况下,HTTP 和 HTTPS 由 Apple 处理,因此不会调用委托(delegate)。要绕过这一点,您需要使用自定义方案来强制调用委托(delegate)方法。

关于ios - 如何使用 AVAssetResourceLoader?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18205588/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com