Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play video with Xamarin forms?

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!

like image 543
Arachnid Avatar asked Mar 16 '15 22:03

Arachnid


2 Answers

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;
      }); 
    };
like image 110
Akshay Kulkarni Avatar answered Oct 04 '22 16:10

Akshay Kulkarni


You can check out the video player component on the Xamarin Forms component store. It allows you to render the native video player on iOS, Android, and Windows Phone. The code snippet below shows the simplest example of just dropping it in and using it. You also have the ability to hook into events like playing, paused, stopped, completed, etc. You can control volume, autoplay, and repeat among other things.

https://github.com/adamfisher/Xamarin.Forms.VideoPlayer

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:o="clr-namespace:Octane.Xam.VideoPlayer;assembly=Octane.Xam.VideoPlayer"
             x:Class="VideoPlayerSamples.VideoPlayerBasicExamplePage"
             Title="Basic Video Player">

    <o:VideoPlayer Source="http://vjs.zencdn.net/v/oceans.mp4" />

</ContentPage>

Disclaimer: This is my component.

like image 22
Adam Avatar answered Oct 04 '22 17:10

Adam