I am trying to get AVFoundation to read from a custom URL. A custom url is running. The code below creates an NSData with a movie file:
NSData* movieData = [NSData dataWithContentsOfURL:@"memory://video"];
I set the AVAssetResourceLoader object using the following code:
NSURL* url = [NSURL URLWithString:@"memory://video"]; AVURLAsset* asset = [[AVURLAsset alloc] initWithURL:url options:nil]; AVAssetResourceLoader* loader = [asset resourceLoader]; [loader setDelegate:self queue:mDispatchQueue];
The send queue is parallel.
Then I will try to extract the first frame from the movie:
AVAssetImageGenerator* imageGen = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; CMTime time = CMTimeMakeWithSeconds(0, 600); NSError* error = nil; CMTime actualTime; CGImageRef image = [imageGen copyCGImageAtTime:time actualTime:&actualTime error:&error]; if (error) NSLog(@"%@", error);
But when I run this, but from the code, I get:
2013-02-21 10:02:22.197 VideoPlayer[501:907] Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x1f863090 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1e575a90 "The operation couldn't be completed. (OSStatus error 268451843.)", NSLocalizedFailureReason=An unknown error occurred (268451843)}
Implementation of the delegate method:
- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest { NSData* data = [NSData dataWithContentsOfURL:loadingRequest.request.URL]; [loadingRequest finishLoadingWithResponse:nil data:data redirect:nil]; return YES; }
Now, my question is: am I implementing this method correctly? Does anyone know what I'm doing right?
Thanks.
EDIT: The movie I collect in its entirety is a single-frame movie.