/// <summary>
        /// Event handler when the user clicks the pick a video button
        /// </summary>
        /// <param name='sender'>
        /// Sender
        /// </param>
        partial void pickVideoBtnClicked(MonoTouch.Foundation.NSObject sender)
        {
            Console.WriteLine("pickVideoBtnClicked");

            picker = new MediaPicker();

            // Check that videos are supported on this device
            if (!picker.VideosSupported)
            {
                ShowUnsupported();
                return;
            }

            //
            // Call PickideoAsync, which returns a Task<MediaFile>
            picker.PickVideoAsync()
            .ContinueWith(t =>              // Continue when the user has picked a video
            {
                if (t.IsCanceled)           // The user canceled
                {
                    return;
                }

                // Play the video the user picked
                InvokeOnMainThread(delegate {
                    moviePlayer = new MPMoviePlayerViewController(NSUrl.FromFilename(t.Result.Path));
                    moviePlayer.MoviePlayer.UseApplicationAudioSession = true;
                    this.PresentMoviePlayerViewController(moviePlayer);
                });
            });
        }
Exemple #2
0
        public async Task PickVideo()
        {
            FileResult result = await MediaPicker.PickVideoAsync(new MediaPickerOptions
            {
                Title = "Wybierz film"
            });

            await EmbedMedia(result, false);
        }
        private async void ProcessButton_Click(object sender, System.EventArgs e)
        {
            if (sender is Button processButton)
            {
                processButton.Enabled = false;
            }

            Uri uri = null;
            try
            {
                var video = await MediaPicker.PickVideoAsync();
                var sourceFile = new File(video.FullPath);
                uri = Android.Net.Uri.FromFile(sourceFile);
                _sourceMedia.uri = uri;
                System.Diagnostics.Debug.WriteLine($"PickVideoAsync COMPLETED: {video.FullPath}");
            }
            catch (FeatureNotSupportedException err)
            {
                // Feature is not supported on the device
                System.Diagnostics.Debug.WriteLine($"PickVideoAsync FeatureNotSupportedException: {err.Message}");

            }
            catch (PermissionException err)
            {
                // Permissions not granted
                System.Diagnostics.Debug.WriteLine($"PickVideoAsync THREW PermissionException: {err.Message}");

            }
            catch (System.Exception err)
            {
                System.Diagnostics.Debug.WriteLine($"PickVideoAsync THREW: {err.Message}");
            }


            //            updateSourceMedia(sourceMedia, uri);
            //           updateTrimConfig(binding.getTrimConfig(), sourceMedia);
            var targetFile = new File(TransformationUtil.GetTargetFileDirectory(ApplicationContext), "transcoded_" + TransformationUtil.GetDisplayName(this, _sourceMedia.uri));
            //var targetFile = new File(FileSystem.CacheDirectory, "transcoded_" + TransformationUtil.GetDisplayName(this, _sourceMedia.uri) + ".mp4");

            // picked media
            updateSourceMedia(_sourceMedia, uri);


            //updateTrimConfig(_trimConfig, _sourceMedia);
            _trimConfig.setTrimEnd(_sourceMedia.duration * 0.5f);
            _trimConfig.setEnabled(true);

            _targetMedia.SetTargetFile(targetFile);
            _targetMedia.setTracks(_sourceMedia.tracks);
            _targetMedia.writeToWav = true;

            //ApplyWatermark(_sourceMedia, _targetMedia, _trimConfig, _transformationState);

            TranscodeAudio(_sourceMedia, _targetMedia, _trimConfig, _transformationState);

        }
        private async void Button_Video_Clicked(object sender, EventArgs e)
        {
            var firestore = DependencyService.Get <IFirestore>();
            var student   = (BindingContext as ElementViewModel).SelectedStudent;
            var storage   = DependencyService.Get <IStorage>();

            _pickVideo = await MediaPicker.PickVideoAsync();

            var videoUrl = await storage.UploadVideo(_pickVideo);

            VideoView.Source = videoUrl;
            student.Video    = videoUrl;

            await firestore.Update(student);
        }
Exemple #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            ImageView image     = FindViewById <ImageView> (Resource.Id.image);
            VideoView videoView = FindViewById <VideoView>(Resource.Id.surfacevideoview);


            //
            // Wire up the take a video button
            //
            Button videoButton = FindViewById <Button> (Resource.Id.takeVideoButton);

            videoButton.Click += delegate
            {
                //
                // The MediaPicker is the class used to
                // invoke the camera and gallery picker
                // for selecting and taking photos
                // and videos
                //
                var picker = new MediaPicker(this);

                // We can check to make sure the device has a camera
                // and supports dealing with video.
                if (!picker.IsCameraAvailable || !picker.VideosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                //
                // TakeVideoAsync is an async API that takes a
                // StoreVideoOptions object with various
                // properties, such as the name and folder to
                // store the resulting video. You can
                // also limit the length of the video
                //
                picker.TakeVideoAsync(new StoreVideoOptions
                {
                    Name          = "MyVideo",
                    Directory     = "MyVideos",
                    DesiredLength = TimeSpan.FromSeconds(10)
                })
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    //
                    // Because TakeVideoAsync returns a Task
                    // we can use ContinueWith to run more code
                    // after the user finishes recording the video
                    //
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and videoviews
                        //
                        image.Visibility     = Android.Views.ViewStates.Gone;
                        videoView.Visibility = Android.Views.ViewStates.Visible;

                        //
                        // Load in the video file
                        //
                        videoView.SetVideoPath(t.Result.Path);

                        //
                        // optional: Handle when the video finishes playing
                        //
                        //videoView.setOnCompletionListener(this);

                        //
                        // Start playing the video
                        //
                        videoView.Start();
                    });
                });
            };

            //
            // Wire up the take a photo button
            //
            Button photoButton = FindViewById <Button> (Resource.Id.takePhotoButton);

            photoButton.Click += delegate
            {
                var picker = new MediaPicker(this);

                if (!picker.IsCameraAvailable || !picker.PhotosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                picker.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    Name      = "test.jpg",
                    Directory = "MediaPickerSample"
                })
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    Bitmap b = BitmapFactory.DecodeFile(t.Result.Path);
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and video views
                        //
                        videoView.Visibility = Android.Views.ViewStates.Gone;
                        image.Visibility     = Android.Views.ViewStates.Visible;

                        //
                        // Display the bitmap
                        //
                        image.SetImageBitmap(b);

                        // Cleanup any resources held by the MediaFile instance
                        t.Result.Dispose();
                    });
                });
            };

            //
            // Wire up the pick a video button
            //
            Button pickVideoButton = FindViewById <Button> (Resource.Id.pickVideoButton);

            pickVideoButton.Click += delegate
            {
                //
                // The MediaPicker is the class used to
                // invoke the camera and gallery picker
                // for selecting and taking photos
                // and videos
                //
                var picker = new MediaPicker(this);

                if (!picker.VideosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                //
                // PickVideoAsync is an async API that invokes
                // the native gallery
                //
                picker.PickVideoAsync()
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    //
                    // Because PickVideoAsync returns a Task
                    // we can use ContinueWith to run more code
                    // after the user finishes recording the video
                    //
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and video views
                        //
                        image.Visibility     = Android.Views.ViewStates.Gone;
                        videoView.Visibility = Android.Views.ViewStates.Visible;

                        //
                        // Load in the video file
                        //
                        videoView.SetVideoPath(t.Result.Path);

                        //
                        // Optional: Handle when the video finishes playing
                        //
                        //videoView.setOnCompletionListener(this);

                        //
                        // Start playing the video
                        //
                        videoView.Start();

                        // Cleanup any resources held by the MediaFile instance
                        t.Result.Dispose();
                    });
                });
            };

            //
            // Wire up the pick a photo button
            //
            Button pickPhotoButton = FindViewById <Button> (Resource.Id.pickPhotoButton);

            pickPhotoButton.Click += delegate
            {
                var picker = new MediaPicker(this);

                if (!picker.PhotosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                picker.PickPhotoAsync()
                .ContinueWith(t =>
                {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    Bitmap b = BitmapFactory.DecodeFile(t.Result.Path);
                    RunOnUiThread(() =>
                    {
                        //
                        // Toggle the visibility of the image and video views
                        //
                        videoView.Visibility = Android.Views.ViewStates.Gone;
                        image.Visibility     = Android.Views.ViewStates.Visible;

                        //
                        // Display the bitmap
                        //
                        image.SetImageBitmap(b);

                        // Cleanup any resources held by the MediaFile instance
                        t.Result.Dispose();
                    });
                });
            };
        }
        public void PickVideoAsync(Action Ready)
        {
            var picker = new MediaPicker();

            picker.PickVideoAsync().ContinueWith(t => SaveFileToMedialibrary(t.Result, ".mp4", () => Ready()), TaskScheduler.FromCurrentSynchronizationContext());
        }
        async Task PickVideoAsync()
        {
            var video = await MediaPicker.PickVideoAsync();

            await LoadVideoAsync(video);
        }
Exemple #8
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            pickPhoto         = new StringElement("Pick Photo");
            pickPhoto.Tapped += () => {
                mediaPicker.PickPhotoAsync().ContinueWith(t => {
                    // User canceled or something went wrong
                    if (t.IsCanceled || t.IsFaulted)
                    {
                        return;
                    }

                    // We get back a MediaFile
                    MediaFile media = t.Result;
                    ShowPhoto(media);
                }, uiScheduler);                 // Make sure we use the UI thread to show our photo.
            };

            takePhoto         = new StringElement("Take Photo");
            takePhoto.Tapped += () => {
                // Make sure we actually have a camera
                if (!mediaPicker.IsCameraAvailable)
                {
                    ShowUnsupported();
                    return;
                }

                // When capturing new media, we can specify it's name and location
                mediaPicker.TakePhotoAsync(new StoreCameraMediaOptions {
                    Name      = "test.jpg",
                    Directory = "MediaPickerSample"
                })
                .ContinueWith(t => {
                    if (t.IsCanceled || t.IsFaulted)
                    {
                        return;
                    }

                    ShowPhoto(t.Result);
                }, uiScheduler);
            };

            takeVideo         = new StringElement("Take Video");
            takeVideo.Tapped += () => {
                // Make sure video is supported and a camera is available
                if (!mediaPicker.VideosSupported || !mediaPicker.IsCameraAvailable)
                {
                    ShowUnsupported();
                    return;
                }

                // When capturing video, we can hint at the desired quality and length.
                // DesiredLength is only a hint, however, and the resulting video may
                // be longer than desired.
                mediaPicker.TakeVideoAsync(new StoreVideoOptions {
                    Quality       = VideoQuality.Medium,
                    DesiredLength = TimeSpan.FromSeconds(10),
                    Directory     = "MediaPickerSample",
                    Name          = "test.mp4"
                })
                .ContinueWith(t => {
                    if (t.IsCanceled || t.IsFaulted)
                    {
                        return;
                    }

                    ShowVideo(t.Result);
                }, uiScheduler);
            };

            pickVideo         = new StringElement("Pick Video");
            pickVideo.Tapped += () => {
                if (!mediaPicker.VideosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                mediaPicker.PickVideoAsync().ContinueWith(t => {
                    if (t.IsCanceled || t.IsFaulted)
                    {
                        return;
                    }

                    ShowVideo(t.Result);
                }, uiScheduler);
            };

            var root = new RootElement("Xamarin.Media Sample")
            {
                new Section("Picking media")
                {
                    pickPhoto, pickVideo
                },
                new Section("Capturing media")
                {
                    takePhoto, takeVideo
                }
            };

            dialogController = new DisposingMediaViewController(root);
            viewController   = new UINavigationController(dialogController);

            window = new UIWindow(UIScreen.MainScreen.Bounds);
            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            return(true);
        }
Exemple #9
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            Button videoButton = FindViewById <Button> (Resource.Id.takeVideoButton);

            videoButton.Click += delegate {
                // The MediaPicker is the class used to invoke the
                // camera and gallery picker for selecting and
                // taking photos and videos
                var picker = new MediaPicker(this);

                // We can check to make sure the device has a camera
                // and supports dealing with video.
                if (!picker.IsCameraAvailable || !picker.VideosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                // TakeVideoAsync is an async API that takes a
                // StoreVideoOptions object with various
                // properties, such as the name and folder to
                // store the resulting video. You can
                // also limit the length of the video
                picker.TakeVideoAsync(new StoreVideoOptions {
                    Name          = "MyVideo",
                    Directory     = "MyVideos",
                    DesiredLength = TimeSpan.FromSeconds(10)
                })
                .ContinueWith(t => {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    RunOnUiThread(() => ShowVideo(t.Result.Path));
                });
            };

            Button photoButton = FindViewById <Button> (Resource.Id.takePhotoButton);

            photoButton.Click += delegate
            {
                var picker = new MediaPicker(this);

                if (!picker.IsCameraAvailable || !picker.PhotosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                picker.TakePhotoAsync(new StoreCameraMediaOptions {
                    Name      = "test.jpg",
                    Directory = "MediaPickerSample"
                })
                .ContinueWith(t => {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    RunOnUiThread(() => ShowImage(t.Result.Path));
                });
            };

            Button pickVideoButton = FindViewById <Button> (Resource.Id.pickVideoButton);

            pickVideoButton.Click += delegate
            {
                // The MediaPicker is the class used to  invoke the camera
                // and gallery picker for selecting and taking photos
                // and videos
                var picker = new MediaPicker(this);

                if (!picker.VideosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                // PickVideoAsync is an async API that invokes
                // the native gallery
                picker.PickVideoAsync().ContinueWith(t => {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    RunOnUiThread(() => ShowVideo(t.Result.Path));
                });
            };

            Button pickPhotoButton = FindViewById <Button> (Resource.Id.pickPhotoButton);

            pickPhotoButton.Click += delegate {
                var picker = new MediaPicker(this);

                if (!picker.PhotosSupported)
                {
                    ShowUnsupported();
                    return;
                }

                picker.PickPhotoAsync().ContinueWith(t => {
                    if (t.IsCanceled)
                    {
                        return;
                    }

                    RunOnUiThread(() => ShowImage(t.Result.Path));
                });
            };
        }