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.
The first step is to right-click on your Solution. Then go to Manage NuGet Packages for Solution.
On the browse tab, type Plugin.MediaManager.Forms then install it on each project in your solution.
Call VideoViewRenderer.Init() on each platform. Let’s put it on MainActivity.cs of our Android project and AppDelegate.cs of iOS.
- You must request AccessWifiState, Internet, MediaContentControl and WakeLock permissions
- 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)
Add the xmlns namespace of Plugin.MediaManager.Forms library.
Start adding the MediaManager.Forms Views on your XAML file by using CachedImage keywords.
Here’s what you can write on your code behind file.
And for the demo of this sample project.
Here’s the online repository of this demo.
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.