예제 #1
0
        static async Task <FileInfo> DoTakePhoto(MediaCaptureSettings settings)
        {
            var result = (await TakeMedia("image/*", MediaStore.ActionImageCapture, enableMultipleSelection: false, settings)).FirstOrDefault();

            await FixOrientation(result);

            return(result);
        }
예제 #2
0
        static async Task <FileInfo> DoTakePhoto(MediaCaptureSettings settings)
        {
            var capture = new CameraCaptureUI();

            capture.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable;
            capture.PhotoSettings.AllowCropping = settings.AllowEditing;

            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);

            return(await result.SaveToTempFile());
        }
예제 #3
0
        /// <summary>Saves a taken video into a local temp folder in the device's cache folder and returns it.</summary>
        public static async Task <FileInfo> TakeVideo(MediaCaptureSettings settings = null, OnError errorAction = OnError.Alert)
        {
            if (!await IsCameraAvailable())
            {
                await errorAction.Apply("No available camera was found on this device.");

                return(null);
            }

            if (!SupportsTakingVideo())
            {
                await errorAction.Apply("Your device does not support recoding video.");

                return(null);
            }

            if (!await Permission.Camera.IsRequestGranted())
            {
                await SuggestLaunchingSettings(errorAction, "Permission was denied to access the camera.");

                return(null);
            }

#if ANDROID
            if (settings?.PurgeCameraRoll == true)
            {
                if (!await Permission.ExternalStorage.IsRequestGranted())
                {
                    await SuggestLaunchingSettings(errorAction, "Permission was denied to access the external storage.");

                    return(null);
                }
            }
#endif

            try
            {
                return(await Thread.UI.Run(() => DoTakeVideo(settings ?? new MediaCaptureSettings())));
            }
            catch (Exception ex)
            {
                await errorAction.Apply(ex, "Failed to capture a video: " + ex.Message);

                return(null);
            }
        }
예제 #4
0
        static async Task <FileInfo> DoTakeVideo(MediaCaptureSettings settings)
        {
            var capture = new CameraCaptureUI();

            capture.VideoSettings.MaxResolution = ToResolution(settings.VideoQuality);
            capture.VideoSettings.AllowTrimming = settings.AllowEditing;
            capture.VideoSettings.Format        = CameraCaptureUIVideoFormat.Mp4;

            if (settings.VideoMaxDuration.HasValue)
            {
                capture.VideoSettings.MaxDurationInSeconds = (float)settings.VideoMaxDuration.Value.TotalSeconds;
            }

            var video = await capture.CaptureFileAsync(CameraCaptureUIMode.Video);

            return(await video.SaveToTempFile());
        }
예제 #5
0
        static async Task <FileInfo> DoLaunchMediaPicker(UIImagePickerControllerSourceType sourceType, string mediaType, MediaCaptureSettings settings)
        {
            Log.For(typeof(Media)).Warning("DoLaunchMediaPicker called");
            var controller = UIRuntime.Window.RootViewController;

            while (controller.PresentedViewController != null)
            {
                controller = controller.PresentedViewController;
            }

            var pickerDelegate = new PickerDelegate(controller, sourceType);

            var picker = CreateController(pickerDelegate, sourceType, mediaType, settings);

            var usePopup = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad &&
                           sourceType == UIImagePickerControllerSourceType.PhotoLibrary;

            if (usePopup)
            {
                pickerDelegate.Popover = new UIPopoverController(picker)
                {
                    Delegate = new PickerPopoverDelegate(pickerDelegate, picker)
                };
                pickerDelegate.DisplayPopover();
            }
            else
            {
                if (OS.IsAtLeastiOS(9))
                {
                    picker.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
                }

                controller.PresentViewController(picker, animated: true, completionHandler: null);
            }

            return(await pickerDelegate.CompletionSource.Task.ConfigureAwait(false));
        }
예제 #6
0
 static Task <FileInfo> LaunchMediaPicker(UIImagePickerControllerSourceType sourceType, string mediaType, MediaCaptureSettings settings)
 {
     Log.For(typeof(Media)).Warning("LaunchMediaPicker called");
     return(Thread.UI.Run(() => DoLaunchMediaPicker(sourceType, mediaType, settings)));
 }
예제 #7
0
 static Task <FileInfo> DoTakeVideo(MediaCaptureSettings settings)
 {
     return(LaunchMediaPicker(UIImagePickerControllerSourceType.Camera, VIDEO_TYPE, settings));
 }
예제 #8
0
        static UIImagePickerController CreateController(PickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, MediaCaptureSettings settings)
        {
            var picker = new UIImagePickerController
            {
                Delegate   = mpDelegate,
                MediaTypes = new[] { mediaType },
                SourceType = sourceType
            };

            if (sourceType != UIImagePickerControllerSourceType.Camera)
            {
                return(picker);
            }

            if (settings.Camera == CameraOption.Front)
            {
                picker.CameraDevice = UIImagePickerControllerCameraDevice.Front;
            }

            picker.AllowsEditing = settings.AllowEditing;

            if (settings.OverlayViewProvider != null)
            {
                var overlay = settings.OverlayViewProvider();
                if (overlay is UIView)
                {
                    picker.CameraOverlayView = overlay as UIView;
                }
            }

            if (mediaType == VIDEO_TYPE)
            {
                if (settings.VideoMaxDuration.HasValue)
                {
                    picker.VideoMaximumDuration = settings.VideoMaxDuration.Value.TotalSeconds;
                }
                picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video;

                switch (settings.VideoQuality)
                {
                case VideoQuality.Medium: picker.VideoQuality = UIImagePickerControllerQualityType.Medium; break;

                case VideoQuality.Low: picker.VideoQuality = UIImagePickerControllerQualityType.Low; break;

                default: picker.VideoQuality = UIImagePickerControllerQualityType.High; break;
                }
            }

            return(picker);
        }
예제 #9
0
 static async Task <FileInfo> DoTakeVideo(MediaCaptureSettings settings)
 {
     return((await TakeMedia("video/*", MediaStore.ActionVideoCapture, enableMultipleSelection: false, settings)).FirstOrDefault());
 }