public void GenerateCGImagesAsynchronously() { // This test deadlocks on Mountain Lion (but works on Lion) // https://gist.github.com/rolfbjarne/1190d97af79e554c298f2c133dfd8e87 TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 9, throwIfOtherPlatform: false); handled = false; mre = new ManualResetEvent(false); ThreadStart main = () => { using (NSUrl video_url = NSUrl.FromFilename(video_asset_path)) using (AVAsset video_asset = AVAsset.FromUrl(video_url)) using (AVAssetImageGenerator aig = new AVAssetImageGenerator(video_asset)) { NSValue[] values = new NSValue[] { NSValue.FromCMTime(CMTime.Zero) }; aig.GenerateCGImagesAsynchronously(values, handler); mre.WaitOne(); } }; var thread = new Thread(main) { IsBackground = true, }; thread.Start(); Assert.True(mre.WaitOne(2000), "wait"); Assert.True(handled, "handled"); }
void UpdateUI() { var formsControl = Element as VideoImagePreview; if (formsControl == null) { return; } if (!string.IsNullOrWhiteSpace(formsControl.VideoUrl)) { var outputTime = new CMTime(); var error = new NSError(); using (var asset = AVAsset.FromUrl(new NSUrl(formsControl.VideoUrl))) using (var assetGenerator = AVAssetImageGenerator.FromAsset(asset)) { var image = assetGenerator.CopyCGImageAtTime(new CMTime(0, 1), out outputTime, out error); if (image != null) { Control?.InvokeOnMainThread(() => ((UIImageView)Control).Image = new UIImage(image)); } } } else { formsControl.Source = "camera.png"; } }
public MemoryStream GenerateThumbImage(string url, long usecond) { var asset = AVAsset.FromUrl(NSUrl.FromFilename(url)); var imageGenerator = AVAssetImageGenerator.FromAsset(asset); imageGenerator.AppliesPreferredTrackTransform = true; var actualTime = asset.Duration; CoreMedia.CMTime cmTime = new CoreMedia.CMTime(usecond, 2000000); NSError error; var cgImage = imageGenerator.CopyCGImageAtTime(cmTime, out actualTime, out error); //AVAssetImageGenerator imageGenerator = new AVAssetImageGenerator(AVAsset.FromUrl((new Foundation.NSUrl(url)))); //imageGenerator.AppliesPreferredTrackTransform = true; //var actualTime = asset.Duration; //CoreMedia.CMTime cmTime = new CoreMedia.CMTime(usecond, 1000000); //NSError error; //var cgImage = imageGenerator.CopyCGImageAtTime(cmTime, out actualTime, out error); //CMTime actualTime; //NSError error; //CGImage cgImage = imageGenerator.CopyCGImageAtTime(new CMTime(usecond, 1000000), out actualTime, out error); var zz = new UIImage(cgImage).AsJPEG().AsStream(); var a = new MemoryStream(); zz.CopyTo(a); return(a); //return ImageSource.FromStream(() => new UIImage(cgImage).AsJPEG().AsStream()); //mageSource.FromStream(() => new UIImage(cgImage).AsPNG().AsStream()); }
ImageSource IVideoUtils.GetVideoThumbnail(string url) { NSUrl videoUrl = NSUrl.CreateFileUrl(url, null); var asset = AVAsset.FromUrl(videoUrl); var imageGenerator = AVAssetImageGenerator.FromAsset(asset); imageGenerator.AppliesPreferredTrackTransform = true; var seconds = asset.Duration.Seconds; CoreMedia.CMTime actualTime; CoreMedia.CMTime cmTime = asset.Duration; var timeScale = asset.Duration.TimeScale; cmTime.Value = (seconds > 5) ? timeScale * 5 : timeScale * 1; NSError error; var imageRef = imageGenerator.CopyCGImageAtTime(cmTime, out actualTime, out error); if (imageRef == null) { return(null); } var uiImage = UIImage.FromImage(imageRef); var img = Xamarin.Forms.ImageSource.FromStream(() => ((uiImage.AsPNG().AsStream()))); return(img); }
public static bool TryGenerateVideoThumbnail2(string localFile, CGSize size, out UIImage image, string extensionHint = ".mov") { image = null; try { const int secondToGet = 1; const int timeScale = 60; var asset = AVAsset.FromUrl(NSUrl.FromFilename(localFile)); var generator = new AVAssetImageGenerator(asset); var time = new CMTime(secondToGet, timeScale); CMTime actualTime; NSError error; var cgImage = generator.CopyCGImageAtTime(time, out actualTime, out error); if (error == null) { image = new UIImage(cgImage); image = UIImageExtensions.ResizeAndDispose(image, size, ResizeMethod.AspectFill, ResizeAlignment.CenterCenter ); return(true); } } catch { } return(false); }
internal static async Task <StorageItemThumbnail> CreateVideoThumbnailAsync(StorageFile file) { AVAsset asset = AVUrlAsset.FromUrl(NSUrl.FromFilename(file.Path)); AVAssetImageGenerator generator = AVAssetImageGenerator.FromAsset(asset); generator.AppliesPreferredTrackTransform = true; NSError error; CMTime actualTime; CMTime time = CMTime.FromSeconds(asset.Duration.Seconds / 2, asset.Duration.TimeScale); CGImage image = generator.CopyCGImageAtTime(time, out actualTime, out error); #if __MAC__ NSMutableData buffer = new NSMutableData(); CGImageDestination dest = CGImageDestination.Create(buffer, UTType.JPEG, 1, null); dest.AddImage(image); return(new StorageItemThumbnail(buffer.AsStream())); #else UIImage image2 = UIImage.FromImage(image); image.Dispose(); UIImage image3 = image2.Scale(new CGSize(240, 240)); image2.Dispose(); return(new StorageItemThumbnail(image3.AsJPEG().AsStream())); #endif }
private void syncedChanged() { if (media == null || media.URL == null) { return; } if (media.URL.Substring(media.URL.Length - 3, 3) == "png") { using (Stream stream = AppDelegate.MomentsManager.FileSystem.getFileStream(media.URL)) { NSData data = NSData.FromStream(stream); this.imageView.Image = UIImage.LoadFromData(data); AppDelegate.MomentsManager.FileSystem.CloseFileStream(stream); } } else { var nsurl = NSUrl.FromFilename((Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + media.URL)); AVAsset asset = AVAsset.FromUrl(nsurl); AVAssetImageGenerator generator = new AVAssetImageGenerator(asset); generator.AppliesPreferredTrackTransform = true; NSError err = null; CMTime outTime = new CMTime(); CMTime requestedTime = new CMTime(2, 1); // To create thumbnail image using (var imgRef = generator.CopyCGImageAtTime(requestedTime, out outTime, out err)){ this.imageView.Image = UIImage.FromImage(imgRef); } } }
public Task <string> CreateThumbnailAsync(string videoPath) { return(Task.Run(() => { var url = NSUrl.FromFilename(videoPath); var asset = AVAsset.FromUrl(url); var assetImageGenerator = AVAssetImageGenerator.FromAsset(asset); assetImageGenerator.AppliesPreferredTrackTransform = true; var time = CMTime.FromSeconds(1, 1); using (var img = assetImageGenerator.CopyCGImageAtTime(time, out CMTime _, out NSError __)) { if (img == null) { Debug.WriteLine($"Could not find file at url: {videoPath}"); return string.Empty; } var outputPath = Path.ChangeExtension(videoPath, ".png"); var fileUrl = NSUrl.FromFilename(outputPath); using (var imageDestination = CGImageDestination.Create(fileUrl, UTType.PNG, 1)) { imageDestination.AddImage(img); imageDestination.Close(); } return outputPath; } })); }
public OperationResult <Stream> GetFirstVideoFrame(string filePath) { var url = NSUrl.CreateFileUrl(filePath, false, null); var asset = new AVUrlAsset(url); var imageGenerator = new AVAssetImageGenerator(asset); imageGenerator.AppliesPreferredTrackTransform = true; CMTime actualTime; NSError error; var cgImage = imageGenerator.CopyCGImageAtTime(new CMTime(0, 1), out actualTime, out error); if (error != null) { return(OperationResult <Stream> .AsFailure(error.ToString())); } if (cgImage != null) { return(OperationResult <Stream> .AsSuccess(new UIImage(cgImage).AsJPEG().AsStream())); } else { return(OperationResult <Stream> .AsFailure("Image generation failed")); } }
public void AppliesPreferredTrackTransform() { using (NSUrl video_url = NSUrl.FromFilename(video_asset_path)) using (AVAsset video_asset = AVAsset.FromUrl(video_url)) using (AVAssetImageGenerator aig = new AVAssetImageGenerator(video_asset)) { // setter was missing see https://bugzilla.xamarin.com/show_bug.cgi?id=5216 aig.AppliesPreferredTrackTransform = true; Assert.True(aig.AppliesPreferredTrackTransform, "AppliesPreferredTrackTransform"); } }
public byte[] GenerateThumbImage(string url, long second) { AVAssetImageGenerator imageGenerator = new AVAssetImageGenerator(AVAsset.FromUrl((new Foundation.NSUrl(url)))); imageGenerator.AppliesPreferredTrackTransform = true; CMTime actualTime; NSError error; CGImage cgImage = imageGenerator.CopyCGImageAtTime(new CMTime(second, 1000000), out actualTime, out error); return(new UIImage(cgImage).AsPNG().ToArray()); }
public void Defaults() { using (NSUrl video_url = NSUrl.FromFilename(video_asset_path)) using (AVAsset video_asset = AVAsset.FromUrl(video_url)) using (AVAssetImageGenerator aig = new AVAssetImageGenerator(video_asset)) { Assert.Null(aig.ApertureMode, "ApertureMode"); Assert.False(aig.AppliesPreferredTrackTransform, "AppliesPreferredTrackTransform"); Assert.That(aig.MaximumSize, Is.EqualTo(CGSize.Empty), "MaximumSize"); Assert.True(aig.RequestedTimeToleranceAfter.IsPositiveInfinity, "RequestedTimeToleranceAfter"); Assert.True(aig.RequestedTimeToleranceBefore.IsPositiveInfinity, "RequestedTimeToleranceBefore"); } }
public ImageSource GenerateThumbImage(string url, long usecond) { AVAssetImageGenerator imageGenerator = new AVAssetImageGenerator(AVAsset.FromUrl((new Foundation.NSUrl(url)))); imageGenerator.AppliesPreferredTrackTransform = true; CMTime actualTime; NSError error; CGImage cgImage = imageGenerator.CopyCGImageAtTime(new CMTime(usecond, 1000000), out actualTime, out error); return(ImageSource.FromStream(() => new UIImage(cgImage).AsPNG().AsStream())); //ImageSource.FromStream(() => new UIImage(cgImage).AsPNG().AsStream()); }
void HandleVideo(MediaFile file) { if (file == null) { return; } var mediaUrl = file.Path; var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var outputFile = Path.Combine(documentsDirectory, Guid.NewGuid().ToString() + ".mp4"); AVUrlAsset asset = new AVUrlAsset(NSUrl.CreateFileUrl(new string[] { mediaUrl })); AVAssetExportSession exportSession = new AVAssetExportSession(asset, AVAssetExportSession.Preset1280x720); var fileUrl = NSUrl.CreateFileUrl(new string[] { outputFile }); exportSession.OutputUrl = NSUrl.CreateFileUrl(new string[] { outputFile }); exportSession.OutputFileType = AVFileType.Mpeg4; LoadingScreen.Show(); LoadingScreen.SetText("Converting"); exportSession.ExportAsynchronously(() => { InvokeOnMainThread(() => { if (exportSession.Error != null) { int i = 3; } AVUrlAsset asset2 = new AVUrlAsset(NSUrl.CreateFileUrl(new string[] { mediaUrl })); AVAssetImageGenerator generator = new AVAssetImageGenerator(asset2); generator.AppliesPreferredTrackTransform = true; var thumbTime = new CMTime(0, 30); NSValue[] vals = new NSValue[] { NSValue.FromCMTime(thumbTime) }; CGSize maxSize = new CGSize(800, 600); //generator.MaximumSize = maxSize; generator.GenerateCGImagesAsynchronously(vals, (requestedTime, imageRef, actualTime, result, error) => { var previewImage = System.IO.Path.Combine(documentsDirectory, Guid.NewGuid() + ".jpg"); NSError err; UIImage.FromImage(new CGImage(imageRef)).AsJPEG(.75f).Save(previewImage, false, out err); InvokeOnMainThread(() => { LoadingScreen.Hide(); VideoPicked?.Invoke(outputFile, previewImage); }); }); }); }); }
UIImage ImageFor(AVAsset avAsset, double time) { AVAssetImageGenerator imageGenerator = AVAssetImageGenerator.FromAsset(avAsset); imageGenerator.AppliesPreferredTrackTransform = true; CMTime actualTime; NSError error = null; var requestedTime = new CMTime((long)time, 100); using (CGImage posterImage = imageGenerator.CopyCGImageAtTime(requestedTime, out actualTime, out error)) return(UIImage.FromImage(posterImage)); }
public void CopyCGImageAtTime_Invalid() { // Mov file is not supported by CopCGImageAtTime so we can test out error param using (NSUrl video_url = NSUrl.FromFilename(does_not_exists_asset_path)) using (AVAsset video_asset = AVAsset.FromUrl(video_url)) using (AVAssetImageGenerator aig = new AVAssetImageGenerator(video_asset)) { // signature errors see https://bugzilla.xamarin.com/show_bug.cgi?id=5218 CMTime actual; NSError error; var img = aig.CopyCGImageAtTime(CMTime.Zero, out actual, out error); Assert.Null(img, "missing"); Assert.True(actual.IsInvalid, "actual"); Assert.NotNull(error, "error"); } }
public static UIImage GetVideoThumbnail(this AVAsset asset) { return(CoreUtility.ExecuteFunction("GetVideoThumbnail", delegate() { AVAssetImageGenerator generator = new AVAssetImageGenerator(asset); generator.AppliesPreferredTrackTransform = true; CMTime ignoreTime = new CMTime(); NSError error = null; CGImage image = generator.CopyCGImageAtTime(new CMTime(1, 1), out ignoreTime, out error); if (error != null) { Container.Track.LogError(error.ConvertToException(), "GetVideoThumbnail"); } return new UIImage(image); })); }
// Video thumbnail code: // https://forums.xamarin.com/discussion/61903/code-snippet-how-to-generate-video-thumbnail public void UpdateContent(string filePath) { this.filePath = filePath; string cache = Common.LocalData.Storage.GetCacheFolder(); string extension = Path.GetExtension(filePath); ImageView.BackgroundColor = UIColor.White; ImageView.ContentMode = UIViewContentMode.ScaleAspectFill; if (extension == ".mov") { // Get thumbnail AVAsset asset = AVAsset.FromUrl(NSUrl.FromFilename(Path.Combine(cache, filePath))); CMTime time = new CMTime(1, 1); using (AVAssetImageGenerator imageGenerator = AVAssetImageGenerator.FromAsset(asset)) { imageGenerator.AppliesPreferredTrackTransform = true; using (CGImage imageRef = imageGenerator.CopyCGImageAtTime(time, out CMTime actualTime, out NSError err)) { if (err != null || imageRef == null) { Console.WriteLine("Error loading thumbnail: " + err?.LocalizedDescription); return; } var thumbnail = UIImage.FromImage(imageRef); ImageView.Image = thumbnail; } } } else if ((new List <string> { ".m4a", ".mp3", ".wav" }).Contains(extension)) { ImageView.Image = UIImage.FromBundle("AudioIcon"); ImageView.BackgroundColor = UIColor.FromRGB(76, 175, 80); ImageView.ContentMode = UIViewContentMode.Center; } else { ImageService.Instance.LoadFile(Path.Combine(cache, filePath)).Into(ImageView); } }
private static UIImage GetVideoThumbnail(AVAssetImageGenerator generator, double seconds, CGSize cellSize) { var time = new CMTime(Clamp(1, 0, (int)seconds), 1); CMTime actual; NSError error; using (var cgImage = generator.CopyCGImageAtTime(time, out actual, out error)) using (var uiImage = new UIImage(cgImage)) { var scaledImage = uiImage.ScaleImage(cellSize, UiKitExtensions.UIImageScaleMode.AspectFill, UiKitExtensions.UIImageAlignment.Center, true); return(scaledImage); } }
public void GenerateCGImagesAsynchronously_Compat() { handled = false; mre = new ManualResetEvent(false); ThreadStart main = () => { using (NSUrl video_url = NSUrl.FromFilename(video_asset_path)) using (AVAsset video_asset = AVAsset.FromUrl(video_url)) using (AVAssetImageGenerator aig = new AVAssetImageGenerator(video_asset)) { aig.GenerateCGImagesAsynchronously(NSValue.FromCMTime(CMTime.Zero), handler); mre.WaitOne(); } }; var asyncResult = main.BeginInvoke(null, null); main.EndInvoke(asyncResult); Assert.True(mre.WaitOne(2000)); Assert.True(handled, "handled"); }
private UIImage GetVideoThumbnailIOS(string path) { try { CMTime actualTime; NSError outError; using (var asset = AVAsset.FromUrl(NSUrl.FromFilename(path))) using (var imageGen = new AVAssetImageGenerator(asset)) using (var imageRef = imageGen.CopyCGImageAtTime(new CMTime(1, 1), out actualTime, out outError)) { return(UIImage.FromImage(imageRef)); } } catch { return(null); } }
/// <summary> /// Creates a thumbnail image from a local video /// </summary> /// <param name="localVideoPath">Full path of the video file, that should exist in the local storage</param> /// <returns>A stream containing the thumbnail bitmap</returns> public Stream CreateVideoThumbnail(string localFilePath) { CoreMedia.CMTime actualTime; NSError outError; using (var asset = AVAsset.FromUrl(NSUrl.FromFilename(localFilePath))) using (var imageGen = new AVAssetImageGenerator(asset)) using (var imageRef = imageGen.CopyCGImageAtTime(new CoreMedia.CMTime(1, 1), out actualTime, out outError)) { if (imageRef == null) { return(null); } var image = UIImage.FromImage(imageRef); return(image.AsPNG().AsStream()); } }
public Stream GetThumbnail(string pathMediaPath) { CMTime actualTime; NSError outError; try { using (var asset = AVAsset.FromUrl(NSUrl.FromFilename(pathMediaPath))) using (var imageGen = new AVAssetImageGenerator(asset)) { imageGen.AppliesPreferredTrackTransform = true; using (var imageRef = imageGen.CopyCGImageAtTime(new CMTime(1, 1), out actualTime, out outError)) { return(UIImage.FromImage(imageRef).AsPNG().AsStream()); } } } catch (Exception exc) { return(null); } }
private byte[] GetImageSource(AVAsset asset) { using (var imageGenerator = new AVAssetImageGenerator(asset)) using (var imageRef = imageGenerator.CopyCGImageAtTime(new CMTime(1, 1), out var actualTime, out var error)) { if (imageRef == null) { return(null); } var image = UIImage.FromImage(imageRef); using (NSData imageData = image.AsPNG()) { var myByteArray = new byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length)); return(myByteArray); } } }
public byte[] GetVideoThumbnail(string path) { try { CMTime actualTime; NSError outError; using (var asset = AVAsset.FromUrl(NSUrl.FromString(path))) using (var imageGen = new AVAssetImageGenerator(asset)) using (var imageRef = imageGen.CopyCGImageAtTime(new CMTime(1, 1), out actualTime, out outError)) { return(RotateImage(UIImage.FromImage(imageRef))); //return UIImage.FromImage(imageRef).AsPNG().ToArray(); } } catch { return(null); } }
public static UIImage GetThumbnailFromVideoURL(NSUrl videoURL) { UIImage theImage = null; var asset = AVAsset.FromUrl(videoURL); var generator = AVAssetImageGenerator.FromAsset(asset); generator.AppliesPreferredTrackTransform = true; NSError error = null; var time = new CMTime(1, 60); CMTime actTime; var img = generator.CopyCGImageAtTime(time, out actTime, out error); if (error != null) { Console.WriteLine(error.ToString()); return(UIImage.FromBundle("videoimage.png")); } Console.WriteLine(img.ToString()); theImage = new UIImage(img); var path = videoURL.RelativePath; var imgData = SuperimposeImage(theImage, UIImage.FromBundle("btn_play.png")).AsJPEG(0.5f); NSError err = null; var jpgFilename = path.Replace(Path.GetExtension(path), "-thumb.jpg"); if (imgData.Save(jpgFilename, false, out err)) { if (err == null) { Console.WriteLine("Thumbnail saved"); } else { Console.WriteLine("error in saving " + err); } } else { Console.WriteLine("Thumbnail not saved"); } return(theImage); }
public UIImage Generate(CGSize size) { var asset = new AVUrlAsset(Url); var generator = new AVAssetImageGenerator(asset) { AppliesPreferredTrackTransform = true, MaximumSize = new CGSize(size.Width * UIScreen.MainScreen.Scale, size.Height * UIScreen.MainScreen.Scale) }; var actualTime = new CMTime(0, 1000); NSError error = null; var cgImage = generator.CopyCGImageAtTime(new CMTime(1, 1000), out actualTime, out error); if (error == null) { return(null); } return(new UIImage(cgImage)); }
public void Config(Moment moment) { this.moment = moment; this.TextLabel.Text = moment.Comment; this.DetailTextLabel.Text = moment.Title; if (moment.Media.Count > 0) { this.icon.Hidden = true; NSData data = null; this.ImageView.Layer.MasksToBounds = true; if (moment.Media [0].Type == "Image") { try { using (Stream imageStream = AppDelegate.MomentsManager.FileSystem.getFileStream(moment.Media [0].URL)) { data = NSData.FromStream(imageStream); AppDelegate.MomentsManager.FileSystem.CloseFileStream(imageStream); } this.ImageView.Image = UIImage.LoadFromData(data); } catch (Exception ex) { Console.WriteLine(ex); } } else { var nsurl = NSUrl.FromFilename((Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + moment.Media [0].URL)); AVAsset asset = AVAsset.FromUrl(nsurl); AVAssetImageGenerator generator = new AVAssetImageGenerator(asset); generator.AppliesPreferredTrackTransform = true; NSError err = null; CMTime outTime = new CMTime(); CMTime requestedTime = new CMTime(2, 1); // To create thumbnail image using (var imgRef = generator.CopyCGImageAtTime(requestedTime, out outTime, out err)){ this.ImageView.Image = UIImage.FromImage(imgRef); } } } else { this.ImageView.Image = null; } }
// Create a video thumbnail preview for the video public static async Task createVideoThumbnailAsync(string videoFilePath) { #if __IOS__ // Extract name of video file, use same name for video thumbnail file string videoFileName = System.IO.Path.GetFileNameWithoutExtension(videoFilePath); string videoThumbnailFilePath = System.IO.Path.Combine( FilePaths.allVideoThumbnailsPath, videoFileName + ".jpg"); await Task.Run(() => { // Adapted from : https://forums.xamarin.com/discussion/61903/code-snippet-how-to-generate-video-thumbnail CMTime actualTime; NSError outError; using (var asset = AVAsset.FromUrl(NSUrl.FromFilename(videoFilePath))) using (var imageGen = new AVAssetImageGenerator(asset)) using (var imageRef = imageGen.CopyCGImageAtTime(new CMTime(1, 1), out actualTime, out outError)) { UIImage videoThumbnail = UIImage.FromImage(imageRef); NSData imgData = videoThumbnail.AsJPEG(); imgData.Save(videoThumbnailFilePath, false); } } ); #endif #if __ANDROID__ // Generate bitmap Bitmap videoBitmap = await createVideoBitmapAsync(100, 100, videoFilePath); // Extract name of video file, use same name for video thumbnail file string videoFileName = System.IO.Path.GetFileNameWithoutExtension(videoFilePath); string videoThumbnailFilePath = System.IO.Path.Combine( FilePaths.allVideoThumbnailsPath, videoFileName + ".jpg"); // Save to file await exportBitmapAsPNGAsync(videoThumbnailFilePath, videoBitmap); #endif }
private void SetVideoCell(AlbumViewCell cell, MediaItem item, int row) { DispatchQueue.DefaultGlobalQueue.DispatchAsync(() => { using (var asset = AVAsset.FromUrl(new NSUrl(item.Path))) using (var generator = AVAssetImageGenerator.FromAsset(asset)) { generator.AppliesPreferredTrackTransform = true; var duration = asset.Duration.Seconds; var scaledImage = GetVideoThumbnail(generator, duration, _cellSize); DispatchQueue.MainQueue.DispatchAsync(() => { if (cell.Tag != row) { return; } cell.Duration = duration; cell.Image = scaledImage; }); } }); }
private UIImage GetVideoThumbnail(string path) { try { CMTime actualTime; NSError outError; using (var asset = AVAsset.FromUrl (NSUrl.FromFilename (path))) using (var imageGen = new AVAssetImageGenerator (asset)) { imageGen.AppliesPreferredTrackTransform = true; using (var imageRef = imageGen.CopyCGImageAtTime (new CMTime (1, 1), out actualTime, out outError)) { return UIImage.FromImage (imageRef); } } } catch { return null; } }