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/4 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/4 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/4 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.

Select the version of Ionic3 or Ionic 4:

Installation Tutorial for Ionic 3 Version

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.html

Installation Tutorial for Ionic 4 Version

UPDATE: Please check this link for Ionic 4 tutorial

 

Create New Ionic 4 Application

 

Install the Cordova and Ionic Native plugins

 

Add preference for YouTube API KEY in config.xml file. See How to Get API Key?

 

Import plugin in app.module.ts file

Add button HTML in home.page.html file

Now add this method in home.page.ts

 

After adding this HTML app will look like this image

2
Leave a Reply

avatar
1 Comment threads
1 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Jolly.exegaston coroleu Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
gaston coroleu
Guest
gaston coroleu

Hi, how can i play this live stream url with your code? https://www.youtube.com/embed/live_stream?channel=UC7Nfr13PyP84jWgU5FS9LGg
Thanks