Introduction In this tutorial, we will learn how to play a video or audio file in Xamarin.Forms applicati...

Video Player App in Xamarin.Forms Video Player App in Xamarin.Forms

Video Player App in Xamarin.Forms

Video Player App in Xamarin.Forms

Introduction

In this tutorial, we will learn how to play a video or audio file in Xamarin.Forms application. This feature is not available by default in Xamarin Forms. So, we need to add an additional plugin to achieve these features. "MediaManager Plugin" offers this functionality."MediaManager Plugin" offers this functionality.


Media Manager

  • Designed to be simple and easy to use
  • Native playback of media files from remote http(s), embedded and local sources
  • Native media notifications and remote controls
  • Queue and playback management by default
  • Playback status (Playing, Buffering, Loading, Paused, Progress)
  • Events for media handling to hook into

Coding Part

Steps

  1. Step 1: Creating new Xamarin.Forms Projects
  2. Step 2: Setting up the Media Manager in Xamarin.Forms .Net Standard Project
  3. Step 3: Implementation of Xamarin Forms - Video Player App

Step 1: Creating new Xamarin.Forms Projects

Create New Project by selecting "New Project" à "Xamarin Cross Platform App" and Clicking "OK".
Note: Xamarin.Forms version should be greater than 5.0.

Then Select Android and iOS Platforms as shown below with Code Sharing Strategy as PCL or .Net Standard and Click OK.

Step 2: Setting up the Media Manager in Xamarin.Forms .Net Standard Project

    In this step, we will see how to setup the plugin.

  • Open the Nuget Manager in the Visual Studio Solution by right click the solution and selecting “Manage Nuget Packages”.
  • Then select below mentioned 2 plugins and check all the projects in the solution, install the plugin.
    • Plugin.MediaManager
    • Plugin.MediaManager.Forms

Step 3: Implementation of Xamarin Forms - Video Player App

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

  • Include the video view control in your xaml file and add the button to perform play/pause operations.
  • We are going to play the video from the url as like in the below snippet.
  • Then add click event to perform the play and pause operations. We need to use the below mentioned code part to peform the play/pause operations using Media Manager
  • The final code behind will look like below.
  • Make sure to call " CrossMediaManager.Init(this, savedInstanceState); " for Android or " CrossMediaManager.Init(this); " for iOS from your platform code before starting playback, otherwise the video View will not be prepared to display the video.

Result

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

1 comment:

  1. Please the source code is missing in github

    ReplyDelete

Please Comment about the Posts and Blog