iOS Question Video Thumbnail

Moosi

Member
Licensed User
Longtime User
Hi,
is there a way to create a Thumbnail from a VideoView?

Thanks for your help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page

   Private ImageView1 As ImageView
End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   Dim no As NativeObject = Me
   Dim bmp As Bitmap = no.RunMethod("thumbnail:", Array(File.Combine(File.DirAssets, "Video.mp4")))
   ImageView1.Bitmap = bmp
   
End Sub

#if objc
@import CoreMedia;
@import AVFoundation;
- (UIImage*)thumbnail:(NSString*) FilePath {
   AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:FilePath] options:nil];
   AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
   gen.appliesPreferredTrackTransform = YES;
   CMTime time = CMTimeMakeWithSeconds(0.0, 600);
   NSError *error = nil;
   CMTime actualTime;

   CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
   UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
   CGImageRelease(image);
   return thumb;
}
#end if
 
Upvote 0

Similar Threads

Top