Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未设置AVAssetResourceLoader委托_Ios_Objective C_Iphone_Delegates_Avfoundation - Fatal编程技术网

Ios 未设置AVAssetResourceLoader委托

Ios 未设置AVAssetResourceLoader委托,ios,objective-c,iphone,delegates,avfoundation,Ios,Objective C,Iphone,Delegates,Avfoundation,我一直在尝试实现AVAssetResourceLoaderDelegate,但到目前为止无法成功设置委托,导致我的委托代码从未被调用 考虑这一点: AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; [asset.resourceLoader setDelegate:[[MyAssetResourceLoaderDelegateCode alloc] init]

我一直在尝试实现AVAssetResourceLoaderDelegate,但到目前为止无法成功设置委托,导致我的委托代码从未被调用

考虑这一点:

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
[asset.resourceLoader setDelegate:[[MyAssetResourceLoaderDelegateCode alloc] init]
                            queue:queue];
NSLog(@"Delegate: %@", asset.resourceLoader.delegate);
此代码始终打印
委托:(空)
。当代理拒绝设置时,如何设置代理?我错过了什么


这发生在模拟器和运行iOS 8的iPhone 5s上

与此对象关联的代理必须采用AVAssetResourceLoaderDelegate协议。 所以代码应该是这样的:

@interface YourClass () <AVAssetResourceLoaderDelegate>
@end

@implementation YourClass

- (void)someMethod
{
    NSURL *url = [NSURL URLWithString:@"...."];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
    [asset.resourceLoader setDelegate:self queue:queue];
}

#pragma mark - AVAssetResourceLoaderDelegate methods

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

}

@end

是的。在我的示例中,
MyAssetResourceLoaderDelegateCode
公开实现了
AVAssetResourceLoaderDelegate
协议及其所有方法,这些方法目前只是日志语句和断点,用于检查它们是否被调用(它们没有)。我知道,委托不是一个强引用,所以它只是被释放。现在,委托已正确设置,但委托对象仍然没有收到有关委托方法的任何消息。有什么想法吗?你需要音频播放器吗?比如_playerItem=[AVPlayerItem playerItemWithAsset:asset];埃特诺,我想玩。然而,我确实创建了这样一个AVPlayerItem,并将其传递给AVPlayer。
@property (nonatomic, strong) MyAssetResourceLoaderDelegateCode *assetObject;

self.assetObject = [MyAssetResourceLoaderDelegateCode new];

[asset.resourceLoader setDelegate:self.assetObject ...];