public Task <IPickedMediaFromGallery> PickVideoAsync() { UIViewController topController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (topController.PresentedViewController != null) { topController = topController.PresentedViewController; } _pickVideoTaskCompletion = new TaskCompletionSource <IPickedMediaFromGallery>(); UIImagePickerController imagePicker = new UIImagePickerController(); imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.MediaTypes = new string[] { UTType.Movie }; imagePicker.FinishedPickingMedia += (sender, args) => { IPickedMediaFromGallery result = null; try { string mediaTypeInfo = args.Info[UIImagePickerController.MediaType].ToString(); if (mediaTypeInfo == _MOVIE_MEDIA_TYPE) { result = HandlePickedMovie(args); } else { result = new PickedMediaFromGallery(); } } catch (Exception exc) { result = new PickedMediaFromGallery() { Exception = exc }; } topController.DismissModalViewController(true); _pickVideoTaskCompletion.SetResult(result); }; imagePicker.Canceled += (sender, args) => { topController.DismissModalViewController(true); _pickVideoTaskCompletion.SetResult(new PickedMediaFromGallery() { Completion = true }); }; topController.PresentModalViewController(imagePicker, true); return(_pickVideoTaskCompletion.Task); }
private void CompleteActionTakeVideoOrImage(IPickedMediaFromGallery completionResult) { try { _takeImageOutputFile.Delete(); } catch (Exception exc) { Debugger.Break(); } TakePhotoOrVideoCompletion.SetResult(completionResult); }
public Task <AttachedFileDataModel> BuildAttachedMediaAsync(IPickedMediaFromGallery mediaFromGallery) => Task <AttachedFileDataModel> .Run(() => { if (mediaFromGallery.MimeType != ProfileMediaService.IMAGE_MEDIA_TYPE && mediaFromGallery.MimeType != ProfileMediaService.VIDEO_MEDIA_TYPE) { Debugger.Break(); throw new InvalidOperationException("Unresolved app media type."); } FileDTO mainSourceFile = new FileDTO(); mainSourceFile.Base64 = mediaFromGallery.DataBase64; mainSourceFile.Name = string.Format("{0}.{1}", Guid.NewGuid(), mediaFromGallery.MimeType == ProfileMediaService.IMAGE_MEDIA_TYPE ? ProfileMediaService.PNG_IMAGE_FORMAT : ProfileMediaService.MP4_VIDEO_FORMAT); FileDTO thumbnail = new FileDTO(); thumbnail.Base64 = mediaFromGallery.DataThumbnailBase64; thumbnail.Name = string.Format("{0}_thumbnail.{1}", Guid.NewGuid(), ProfileMediaService.PNG_IMAGE_FORMAT); return(new AttachedFileDataModel() { File = mainSourceFile, Thumbnail = thumbnail, MimeType = mediaFromGallery.MimeType }); });