I've been trying to implement AVAssetResourceLoaderDelegate but so far have been unable to successfully set the delegate, causing my delegate code to never get called.
Consider this:
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
[asset.resourceLoader setDelegate:[[MyAssetResourceLoaderDelegateCode alloc] init]
queue:queue];
NSLog(@"Delegate: %@", asset.resourceLoader.delegate);
This code always prints Delegate: (null). How do I set the delegate when the delegate refuses to be set? What am I missing?
This occurs on the simulator and on an iPhone 5s running iOS 8.
The delegate you associate with this object must adopt the AVAssetResourceLoaderDelegate protocol. So the code should be like this:
@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
OR
if you have separate delegate MyAssetResourceLoaderDelegateCode somewhere then you have to keep the strong reference to the object MyAssetResourceLoaderDelegateCode you created and pass it as a delegate. When you do [asset.resourceLoader setDelegate:... The resourceLoader is just have a weak reference to the object you made. So, the code can be:
@property (nonatomic, strong) MyAssetResourceLoaderDelegateCode *assetObject;
self.assetObject = [MyAssetResourceLoaderDelegateCode new];
[asset.resourceLoader setDelegate:self.assetObject ...];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With