private async void CaptureVideo()
        {
            ///data/user/0/com.companyname.mediapickerspike/files/ed3f5961-4554-4a3f-ba3d-dd44020745562062848124215052442.mp4
            try
            {
                var video = await MediaPicker.CaptureVideoAsync(new MediaPickerOptions {
                    Title = "Record Video"
                });

                var stream = await video.OpenReadAsync();

                var documentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var localPath    = Path.Combine(documentPath, video.FileName);
                File.WriteAllBytes(localPath, stream.ReadAllBytes());
                Videos.Add(new UserVideo
                {
                    FullPath = localPath,
                    VideoId  = video.FileName,
                    Name     = $"Test Video {Videos.Count}"
                });
            } catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #2
0
        public async Task CaptureVideo()
        {
            FileResult result = await MediaPicker.CaptureVideoAsync(new MediaPickerOptions
            {
                Title = "Nagraj wideo"
            });

            await EmbedMedia(result, false);
        }
 async Task CaptureVideoAsync()
 {
     try
     {
         var video = await MediaPicker.CaptureVideoAsync();
         await LoadVideoAsync(video);
     }
     catch (Exception ex)
     {
     }
 }
Exemple #4
0
        /// <summary>
        /// capture
        /// </summary>
        public void Capture(bool captureVideo, MediaPickerOptions options = null)
        {
            FileResult file = null;

            Task.Run(async() =>
            {
                try
                {
                    if (captureVideo)
                    {
                        file = await MediaPicker.CaptureVideoAsync(options);
                    }
                    else
                    {
                        file = await MediaPicker.CapturePhotoAsync(options);
                    }
                    await LoadPhotoAsync(file);
                }
                catch (Exception ex)
                {
                    // Other error has occurred.
                }
            });
        }
        async Task SelectVideoAsync()
        {
            try
            {
                polling = true;

                //Enable if you want to pick up video from Gallery
                //var video = await MediaPicker.PickVideoAsync();

                // Capture de video from camera
                var video = await MediaPicker.CaptureVideoAsync();
                await LoadPhotoAsync(video);

                //Get and show de size of the file
                var sizeSrc = new FileInfo(video.FullPath).Length;
                sizeSrcLabel.Text = sizeSrc.ToString();

                //Load inferface from native code
                var convertVideo = DependencyService.Get <IConvertVideoService>();

                //Check the bitrate and define if you need to compress the file
                bool needConvert = convertVideo.NeedCompress(video.FullPath, 10);
                needConvert = true;
                string exportPath     = String.Empty;
                string exportFilePath = String.Empty;

                //Compress video if bitrate is langer
                if (needConvert)
                {
                    //Define the temp name
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        exportPath     = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        exportFilePath = Path.Combine(exportPath, "compressed_video.mp4");
                    }
                    else
                    {
                        exportFilePath = Path.Combine(FileSystem.CacheDirectory, "compressed_" + video.FileName);
                    }

                    //Converting Code
                    Device.StartTimer(TimeSpan.FromMilliseconds(1000), () =>
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            percentLabel.Text = percentConvert.ToString() + " %";
                        });
                        return(polling);
                    });

                    convertVideo.Percent += (object sender, float e) =>
                    {
                        percentConvert = e;
                    };

                    convertVideo.Success += (object sender, bool e) =>
                    {
                        var newVideo = new FileInfo(exportFilePath);
                        var sizeNew  = newVideo.Length;
                        sizeDestLabel.Text = sizeNew.ToString();
                        polling            = false;
                    };

                    convertVideo.Fail += (object sender, string message) =>
                    {
                        //Do something when convert fail
                        throw new NotImplementedException();
                    };

                    await convertVideo.CompressVideo(PhotoPath, exportFilePath);
                }
                else
                {
                    //Do something when bitrate is slow
                    throw new NotImplementedException();
                }
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                // Feature is now supported on the device
                Console.WriteLine(fnsEx.ToString());
            }
            catch (PermissionException pEx)
            {
                Console.WriteLine(pEx.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}");
            }
        }