Question

I have a video file stored in the tmp directory, the url is valid, and the video is valid. The problem is that i get null value in the resultBlock no matter what url i pass in.

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];

[al assetForURL:url resultBlock:^(ALAsset *asset) {
   NSLog(@"%@", asset); //asset is null/nil 
} failureBlock:^(NSError *error) {
   NSLog(@"Failed creating asset from url with error: %@", [error description]);
}];
Was it helpful?

Solution

If your video is in the tmp directory then it isn't in the asset store associated with the ALAssetsLibrary and you will need to access the video data using standard file loading APIs (like NSFileManager / NSData dataWithContentsOfURL:....

If you want the video to be managed by the ALAssetsLibrary, you need to call writeVideoAtPathToSavedPhotosAlbum:completionBlock: to import the video. The completionBlock will then provide you with an asset library URL (assetURL) which can be used to retrieve the video later (from ALAssetsLibrary).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top