Ionic 3 | How to Add YouTube Video Player Native Plugin in Ionic 3.x Native Applications

In this tutorial, we will create an Ionic 3 application to demonstrate How to Add YouTube Video Player. We will Install the Cordova plugin and Ionic Native Wrapper to add functionality in Ionic 3 Application by using which YouTube’s Player can be opened to Play any YouTube video right from the Ionic application itself. To play a Video we need to provide the ID of video which we want to play.

Let’s start with implementation and create an application to play YouTube Videos from Ionic 3 Application.

Before we start with application make sure that your system is having updated version of NodeJS installed.

Create a new Ionic Application

Install latest version of Ionic and Cordova CLI.

Now we will create a new blank application

After the application is created, go to the root using the CD command

If your system is having Visual Studio code(VS Code) installed, use  $ code .  command to open the project in VS Code

Install the Cordova and Ionic Native plugins

We will install YouTube Video Player Cordova plugin and Ionic Native Wrapper to support plugin in our Angular application.

Add preference in config.xml with YouTube Data V3 API

In config.xml we need to add a preference configuration variable with the API key

Click here to know more on How to get API key?

Import Ionic Native Plugin in the Main Module

Now we will import YouTube Video Player native plugin in app.module.ts and add in providers array

Add method in Home Component

Import plugin then add in contractor list to use in the home component. Replace below code in home.ts

 

Add Button in Home HTML to Open Video

In home.html, we will add a button to call openVideo method which we added above in home.ts

After adding this HTML app will look like this image

Leave a Reply

avatar
  Subscribe  
Notify of