I'm creating an app using CodenameOne and have to use an ios native interface to generate some video thumbnails. Here is the code I am using in iOS:
-(NSData*)createThumbnailFromMp4:(NSString*)param{
NSURL *mediaURL = [NSURL fileURLWithPath:param];
AVAsset *asset = [AVAsset assetWithURL:mediaURL];
CMTime duration = [asset duration];
CMTime snapshot = CMTimeMake(duration.value / 2, duration.timescale);
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:snapshot actualTime:nil error:nil];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return UIImagePNGRepresentation(thumbnail);
}
The param passed in is the full path to the video, but all I get back when I call this is a 0 length byte[]. Here is the code from CodenameOne:
byte[] thumbnailImage = tg.createThumbnailFromMp4(FileSystemStorage.getInstance().getAppHomePath() + movePath);
Where movePath is just the file name of the locally stored video.