DEV Community

Logesh Palani
Logesh Palani

Posted on • Originally published at logeshpalani.blogspot.com on

Video Player App in Xamarin.Forms

*Introduction *

               In this article, we are going to play a video and an audio in Xamarin.Forms application.There is no default function available for playing the video or audio. So, we need to add a plugin for this.

*Nuget Packages *

Xamarin.Forms = search "Plugin.MediaManager.Forms".

Xamarin.Android = search "Plugin.MediaManager".

MediaManager Cross-platform media plugin features

  • Designed to be simple and easy to play
  • Stand alone for easy integration with existing projects and frameworks
  • Native playback of media files from remote and local sources
  • Native media notifications and remote controls
  • Playback status(Playing, Buffering, Loading, Paused, Progress)

Output 🐱‍👤

Step 1

You can create Xamarin.Forms app by going to File >> New >> Visual C# >>Cross platform >> Cross-platform App (Xamarin.Native or Xamarin.Forms), give the application name, and press OK.

(Project Name : VideoPlayerApp)

Step 2 :

         After the project creation, add the following NuGet Packages to your project.
  • Plugin.MediaManager
  • Plugin.MediaManager.Forms

          For that, go to Solution Explorer and select your solution. Right-click and select Manage NuGet Packages for the Solution". Now, select the following NuGet Package and select your project to install it.
    
  • Plugin.MediaManager.Forms

Step 3 :

          In this step, add a VideoView control to your project. For that, go to Solution Explorer \>\> VideoPlayerApp (PCL) \>\> double click on MainPage.Xaml. After opening this, you can add VideoView assembly and XAML code to your project.

Write the code as given below.

Assembly

XAML code

Step 4 :

Next, open Solution Explorer >>VideoPlayerApp(PCL) >> MainPage.xaml.cs page and double-click to open its design view. The code is given below.

Code Behind

Step 5 :

Make sure to call "VideoViewRenderer.Init(); " from your platform code before starting playback, otherwise the video View will not be prepared to display the video.

Android Project

Add Android project by going to Solution Explorer >> VideoPlayerApp.Droid >>MainActivity.cs and double-click to open its design View. Here is the code.

MainActivity.cs Code

IOS Project
** ** Add iOS project. For that, go to Solution Explorer >> VideoPlayerApp.IOS >>AppDelegate.cs and click open AppDelegate.cs. Here is the code for this page.

AppDelegate.cs Code

Universal Windows Project

            Add Universal Windows project. For that, open Solution Explorer \>\>VideoPlayerApp.UWP \>\> MainPage.xaml.cs and click open MainPage.xaml.cs.

Add the below given code to this page.

MainActivity.xaml.cs code

Step 6 :

** Click ' F5 ' or "Build " to run your projects. Running this project, you will have the result like below.**

** Finally, we have successfully created a Xamarin.Forms VideoPlayerApp Application.**

Top comments (0)