Using iOS native interface to create video thumbnail always returning empty byte array

23 views
Skip to first unread message

kazz...@gmail.com

unread,
Jul 4, 2016, 10:14:16 PM7/4/16
to CodenameOne Discussions

I'm creating an app using CodenameOne and have to use an ios native interface to generate some video thumbnails. 

I can't see the iOS logs as I don't have a Mac but as far as anyone has said the iOS code is correct so I feel that it's something to do with either the passing of file paths from CodenameOne to a native interface or the returning of NSData into a byte[] in Codename One. 

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. 

Shai Almog

unread,
Jul 5, 2016, 12:42:41 AM7/5/16
to CodenameOne Discussions, kazz...@gmail.com
Reply all
Reply to author
Forward
0 new messages