private async void TakeVideo_OnClicked(object sender, EventArgs e) { try { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported) return; var mediaOptions = new StoreVideoOptions() { Directory = "Receipts", Name = $"{DateTime.Now:T}.mp4".Replace(":", "-") }; //var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions); var file = await CrossMedia.Current.TakeVideoAsync(mediaOptions); CurrentViewModel.VideoPath = file.Path; await CurrentViewModel.UploadVideoAsync(file); VideoPlayer.Source = CurrentViewModel.VideoPath; } catch (Exception ex) { // ignored } }
/// <summary> /// Take a video with specified options /// </summary> /// <param name="options">Video Media Options</param> /// <returns>Media file of new video or null if canceled</returns> public async Task<MediaFile> TakeVideoAsync(StoreVideoOptions options) { if (!initialized) await Initialize(); if (!IsCameraAvailable) throw new NotSupportedException(); options.VerifyOptions(); var capture = new CameraCaptureUI(); capture.VideoSettings.MaxResolution = GetResolutionFromQuality(options.Quality); capture.VideoSettings.MaxDurationInSeconds = (float)options.DesiredLength.TotalSeconds; capture.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Video); if (result == null) return null; string aPath = null; if (options?.SaveToAlbum ?? false) { try { string fileNameNoEx = Path.GetFileNameWithoutExtension(result.Path); var copy = await result.CopyAsync(KnownFolders.VideosLibrary, fileNameNoEx + result.FileType, NameCollisionOption.GenerateUniqueName); aPath = copy.Path; } catch (Exception ex) { Debug.WriteLine("unable to save to album:" + ex); } } return new MediaFile(result.Path, () => result.OpenStreamForReadAsync().Result, albumPath: aPath); }
/// <summary> /// Take a video with specified options /// </summary> /// <param name="options">Video Media Options</param> /// <returns>Media file of new video or null if canceled</returns> public async Task<MediaFile> TakeVideoAsync(StoreVideoOptions options) { if (!IsCameraAvailable) throw new NotSupportedException(); if (!(await RequestStoragePermission().ConfigureAwait(false))) { return null; } VerifyOptions(options); return await TakeMediaAsync("video/*", MediaStore.ActionVideoCapture, options); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <returns></returns> public Intent GetTakeVideoUI(StoreVideoOptions options) { if (!IsCameraAvailable) throw new NotSupportedException(); VerifyOptions(options); return CreateMediaIntent(GetRequestId(), "video/*", MediaStore.ActionVideoCapture, options, tasked: false); }
/// <summary> /// Take a video with specified options /// </summary> /// <param name="options">Video Media Options</param> /// <returns>Media file of new video or null if canceled</returns> public Task<MediaFile> TakeVideoAsync(StoreVideoOptions options) { throw new NotSupportedException(); }
/// <summary> /// Take a video with specified options /// </summary> /// <param name="options">Video Media Options</param> /// <returns>Media file of new video or null if canceled</returns> public async Task<MediaFile> TakeVideoAsync(StoreVideoOptions options) { if (!initialized) await Initialize(); if (!IsCameraAvailable) throw new NotSupportedException(); options.VerifyOptions(); var capture = new CameraCaptureUI(); capture.VideoSettings.MaxResolution = GetResolutionFromQuality(options.Quality); capture.VideoSettings.MaxDurationInSeconds = (float)options.DesiredLength.TotalSeconds; capture.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Video); if (result == null) return null; return new MediaFile(result.Path, () => result.OpenStreamForReadAsync().Result); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <returns></returns> public Task<MediaFile> TakeVideoAsync(StoreVideoOptions options) { return Task.FromResult<MediaFile>(null); }
/// <summary> /// Take a video with specified options /// </summary> /// <param name="options">Video Media Options</param> /// <returns>Media file of new video or null if canceled</returns> public Task<MediaFile> TakeVideoAsync(StoreVideoOptions options) { if (!IsTakeVideoSupported) throw new NotSupportedException(); if (!IsCameraAvailable) throw new NotSupportedException(); VerifyCameraOptions(options); return GetMediaAsync(UIImagePickerControllerSourceType.Camera, TypeMovie, options); }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <returns></returns> public MediaPickerController GetTakeVideoUI(StoreVideoOptions options) { if (!IsTakeVideoSupported) throw new NotSupportedException(); if (!IsCameraAvailable) throw new NotSupportedException(); VerifyCameraOptions(options); var d = new MediaPickerDelegate(null, UIImagePickerControllerSourceType.Camera, options); return SetupController(d, UIImagePickerControllerSourceType.Camera, TypeMovie, options); }