We are making a chat app and for video thumbnail we use the following code. But it crashes in random cases.
NSArray *arrjid = [jid componentsSeparatedByString:@"@"];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
NSString *strdate = [dateFormatter stringFromDate:[NSDate date]];
NSString *strname = [NSString stringWithFormat:@"%@_%@_file.mov",arrjid[0],strdate];
NSString *videoPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:strname];
[videoData writeToFile:videoPath atomically:YES];
if([[NSFileManager defaultManager] fileExistsAtPath:videoPath])
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath] completionBlock:^(NSURL *assetURL, NSError *error) {
}];
}
Every time it crashes on the writeVideoAtPathToSavedPhotosAlbum line and it gives only "bad access error".
Does anyone have an idea related to this?
ALAssetsLibrary library method writeVideoAtPathToSavedPhotosAlbum:completionBlock: is deprecated, you can use PHPhotoLibrary instead.
try this
Also check if you have Photo Library usage description in info plist with following key
UPDATE
For fetching thumbnail from video you can use AVAssetImageGenerator class from AVFoundation framework