Videos, Xamarin

Playing videos using Xamarin Forms

Getting videos to play in our application is a dynamic way to display important content that can help us to offer a better user experience, avoiding users to exit the application to see video resources that requires the application at runtime.

In the post, we will be explaining this topic, in the following points:

? Platform implementation

? Adding the video player in the XAML

? Beginning coding

 ? Platform support


First of all… What do I need?

  • Add from NuGet Package the plugin: Plugin.MediaManager.Forms


Platform Implementation

To use it, you must initialize it in each platform:

▪ Android    ➡   MainActivity.cs

▪ IOS            ➡   AppDelegate.cs    

▪ Windows  ➡   MainPage.xaml.cs   


Let’s Start!

Adding the video player in the XAML

To use the Video Player you must add the following namespace:

After, you have to add the Video Player control:

⚠ Important: Every time that you use this control you must specify the width and height for the player or you may run into a situation where it won’t show up.


Beginning coding

Here you just have to handle the action that you want to do in the video control, here I show you the most important actions you need to do in a Video Player, I will be using CrossMediaManager Class, to show the Play and Stop method.

▶ Play: To start playing the video recording, you just have to use the Play method. Let’s see:

▪ Url:  Is the URL that the video control, will reproduce in our application. For example:

▪ MediaFileType: Is the type of file that you will reproduce. Here you can select between MediaFileType.Video and MediaFileType.Audio. (Yes, you can reproduce audios too).

Implementing the Play method:

⏹ Stop: To stop the video recording, you just have to use the Stop method, as I show below:


Example:

Xaml

C# code:


Platform Support


Good luck with your implementation.

Spanish post: https://medium.com/@reyes.leomaris/reproduciendo-videos-en-xamarin-forms-26e0f223948d

References: https://github.com/martijn00/XamarinMediaManager

Tagged , ,

2 thoughts on “Playing videos using Xamarin Forms

Leave a Reply

Your email address will not be published. Required fields are marked *