How to play video with Xamarin forms?

Arachnid picture Arachnid · Mar 16, 2015 · Viewed 8.6k times · Source

I have implemented the examples here: https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Camera And am able to get an image from the camera successfully.

Additionally i have implemented the select video - but have no way to play the video...

I ended up putting up a browser window and playing the video off a remove page after uploading it. However, this is not idea, i want to play the video in the app after choosing it from the file system or the camera itself.

Has anyone managed to do this xamarin forms/forms labs without having to implement it in every single platform manually?

And if that is the ONLY way to do it, any examples of this? Thank you very much!

Answer

Akshay Kulkarni picture Akshay Kulkarni · Apr 13, 2016

Try using Media Plugin

This one is easy to use and handy see the documentation given on above page

media Plugin is a simple cross platform plugin to take photos and video or pick them from a gallery from shared code.

Usage

Via a Xamarin.Forms project with a Button and Image to take a photo:

  takePhoto.Clicked += async (sender, args) =>
    {

      if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.PhotosSupported)
      {
        DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
        return;
      }

      var file = await CrossMedia.Current.TakePhotoAsync(new Media.Plugin.Abstractions.StoreCameraMediaOptions
        {

          Directory = "Sample",
          Name = "test.jpg"
        });

      if (file == null)
        return;

      DisplayAlert("File Location", file.Path, "OK");

      image.Source = ImageSource.FromStream(() =>
      {
        var stream = file.GetStream();
        file.Dispose();
        return stream;
      }); 
    };