I am excited to announce a cross-platform video player on the Xamarin Component Store. This new Xamarin Forms component gives developers the ability to render the native video player for iOS, Android, and Windows Phone all from XAML, shared code, or a portable class library (PCL). I find video encoding and streaming to be a fun challenge no matter what I am developing for and was excited to learn there is currently no comprehensive solution to cross-platform video playback with Xamarin Forms.

I am hoping developers will enjoy improved productivity when developing mobile applications requiring video because you can now control many aspects of the playback experience from shared code. For example, you can register for events (Playing, Paused, Stopped, TimeElapsed, etc.) all from a single shared code base. The goal is to provide video playback that’s easy to use without having to handle the idiosyncrasies of each platform’s media framework.

Getting Started

If you are a Xamarin mobile developer, the only thing you need to do to get a working native video player on every platform is to install the component following the getting started section on the Xamarin Component Store. Literally the one line declaration below is sufficient to supercharge your apps with video.

Specifying the Video Source

You may notice the Source property takes a VideoSource object. This was built to have very similar design and behavior to Xamarin’s ImageSource class. You could literally follow the tutorial for working with images and just swap out the word ImageSource for VideoSource. This means you have the ability to specify a video’s file location as a local file system path, a remote URL or as an embedded resource from an assembly.

When working with embedded resources though, I took it one step further and made it a little more extensible when attempting to locate resources. The order of searching assemblies to find embedded resources when calling VideoSource.FromResource(“MyVideo.mp4”) has the same behavior as calling ImageSource.FromResource(…) but the entry assembly (your iOS, Android, or Windows Phone proxy application) is also searched in the event no other match is found.

Playing YouTube and Vimeo Videos

The major video hosting sites allow developers to play content hosted by them in the applications they build. The Xamarin Forms video player sample application (called Chill Player) comes with some convenience XAML markup extensions that can convert YouTube and Vimeo video ID’s into the playback stream URLs compatible with the video player on each platform.

It’s important to note that using direct stream URLs in this manner may be against the terms of use for these sites. As such, this experimental feature is merely a convenience and will likely see low priority support going forward. Both YouTube and Vimeo expose public APIs which you are encouraged to integrate for use with this video player component.

Trial

You can download the sample application and run it on all three platforms to try out the demo. The trial version limits video playback to 15 seconds. You can download the trial on the Xamarin Component Store or on Nuget.org. In trial mode, the video player just fails after 15 seconds of playback.

Support

If you need support and have purchased at least one copy of the component, you can open and browse tickets here.

23 Comments A Cross-Platform Video Player for Xamarin Forms

  1. Troy

    Hi Adam, your component looks nice. Wondering if there is a source option for purchasing? We may need to customize things as well as capture events on the playback time of the video.

    1. Adam

      Currently there is no source option but you do have full customization of the native player when you run into those one off scenarios. You can create your own Xamarin Forms custom renderer by extending the VideoPlayerRenderer in your native plaform library. I would also recommend checking out the events documentation as there is already a TimeElapsedInterval event you can hook into to do something at predefined intervals.

  2. Per

    Hi Adam,

    should it also work with a rtp stream coming from a Wowza server?

    Regards,

    Per

    1. Adam

      Under the hood it is using the native video player of each platform so depending on which platform you are talking about will dictate what is supported out of the box. You can of course extend the VideoPlayerRenderer if you want to add custom behavior for a platform that doesn’t have it.

    1. Adam

      I doubt anyone is making an effort to support flash since Apple and Google have started to nix it in their products. I would recommend converting to a more universal format that is friendly across all of the mobile platforms like MP4 perhaps.

  3. Cesar De la Torre

    Hey Adam, Does your control support AZURE MEDIA SERVICES (either on-demand or live streaming)?

    1. Adam

      I am not familiar with the specifics of Azure Media Services but if you are able to get remote URLs from it, I would say yes. The best thing to do is to download the trial version of the video player and plug in a URL from their service to test it. Playback fails after 15 seconds in trial mode.

  4. Karsten

    Hi Adam,

    When the VideoPlayer is shown on the page, I get only a black box. Only when I click on it, the video starts and I see the control buttons. Is that a bug? DisplayControls is set to True.
    Is it possible to show the first image of the video and the buttons directly?
    Regards, Karsten

    1. Adam

      The default behavior for most platforms is to show the controls when the video player is tapped and then hide them again after a few seconds until the user taps the video player again to provide an unobstructed playback surface. DisplayContols is a way to completely turn off the controls so they never appear which is useful if you are going to wire up your own buttons through XAML commands. If you want the controls to stay pinned on the screen the entire time, that is custom behavior you will need to extend the VideoPlayerRenderer and override the media controller.

  5. jas

    Is there any planned support for UWP? I am curious for supporting an app on both mobile and “Standard” Windows 10.

      1. Adam

        You can play remote URLs, embedded resources packaged with your app, or raw streams you load into memory yourself. You can checkout the Chill Player example application’s main menu. It uses an embedded resource stream packaged in the app’s PCL on how to set it up.

    1. Adam

      UWP support was added a few versions back 🙂 You should be able to test it out by downloading the trial from the Xamarin Component Store or from nuget.org.

      1. JAS

        very kool, then. I would recommend you update the meta tags in the compent store then to list UWP/Win10 as supported 🙂

  6. Sama Patel

    Is there any pause or stop method that i can stop or pause by coding when user speak pause or stop?

    1. Adam

      It sounds possible. I don’t know what the APIs are for Google or Siri voice API’s but if you are able to listen for specific words, then you can simply invoke the play()/stop() methods on the video player inside those events.

    1. Adam

      That is not currently supported out of the box but may be added in the future. You can always extend the native VideoPlayerRenderer on the platform you want to add full screen support for.

  7. Alessandro Del Sole

    Hi Adam,
    could you please provide an example of how to open local videos rather than embedding resources? Is there any issues with Android to care about? I’m really interested but I was unable to play local, offline videos on Android. Thanks in advance.

    1. Adam

      If you download the trial from the Xamarin Component Store, the Chill Player example app shows an example of local playback. The main menu background is one example of a video file packaged with the app in the shared PCL. The key thing to remember is the video file should be marked as an embedded resource and you create a video source by calling VideoSource.FromResource("MyVideo.mp4");.

Comments are closed.