Xamarin Forms 101: How to include a video player in your Xamarin App

Are looking for a tutorial on how to implement a video player in your Xamarin Forms app?

In this post, you will learn the simple step-by-step process of including a video player in your Xamarin Forms.

Step 1:

The first step is to right-click on your Solution. Then go to Manage NuGet Packages for Solution.

 

Step 2:

On the browse tab, type Plugin.MediaManager.Forms then install it on each project in your solution.

 

Step 3:

Call VideoViewRenderer.Init() on each platform. Let’s put it on MainActivity.cs of our Android project and AppDelegate.cs of iOS.

 

Step 4:

Android:

  • You must request AccessWifiState, Internet, MediaContentControl and WakeLock permissions

iOS:

  • For the audio to continue to play in the background, you have to add the Audio and Airplay Background mode to your Info.plist
  • If you want to enable RemoteControl features, you will have to override UIApplication.RemoteControlReceived(UIEvent) and forward the event to the MediaManagerImplementation.MediaRemoteControl.RemoteControlReceived(UIEvent) method. See the sample application for more details.
  • If you are playing audio from an HTTP resource, you have to take care of ATS.
  • If you want to display an artwork/cover that is embedded into an MP3 file, make sure that you use ID3 v2.3 (not v2.4)

 

Step 5:

Add the xmlns namespace of Plugin.MediaManager.Forms library.

 

Step 6:

Start adding the MediaManager.Forms Views on your XAML file by using CachedImage keywords.

 

Step 7:

Here’s what you can write on your code behind file.

 

Step 8:

And for the demo of this sample project.

Here’s the online repository of this demo.

GitHub: https://github.com/webmasterdevlin/VideoPlayerDemo

 

Wrapping it up, creating a video player in your Xamarin Forms app is not that complicated. Thanks to Martijn van Dijk and the other contributors in this open source library who are making our development tasks easier.

Post A Comment