public static bool TryGenerateVideoThumbnail(string localFile, CGSize size, out UIImage image) { image = null; try { const float secondToGet = 1.0f; using (var player = new MPMoviePlayerController(NSUrl.FromFilename(localFile))) { image = player.ThumbnailImageAt( secondToGet, MPMovieTimeOption.NearestKeyFrame ); image = UIImageExtensions.ResizeAndDispose(image, size, ResizeMethod.AspectFill, ResizeAlignment.CenterCenter ); player.Stop(); } } catch { return(false); } return(true); }
public async Task <Stream> GetThumbnailAsync(CancellationToken ct, ThumbnailMode mode) { var stream = await UIThread.Current.Run(async ict => { try { var fileUrl = NSUrl.FromFilename(this.Path); var movie = new MPMoviePlayerController(fileUrl); movie.ShouldAutoplay = false; movie.Stop(); var image = movie.ThumbnailImageAt(1.0, MPMovieTimeOption.Exact); movie.SafeDispose(); return(image.AsPNG().AsStream()); } catch (Exception e) { this.Log().Error("The thumbnail could not retrieved.", e); return(null); } }, ct); return(stream); }