Play YouTube Video In Ionic 5 Angular Application

Share the post

Hello All, In the last Ionic we had discussed How to create a pdf viewer in the Ionic 5 application. Now, In this Ionic 5 tutorial, You will learn How to play YouTube Video in the Ionic 5 angular application.

We will use the YouTube Video player plugin which is available for Ionic-native. This plugin is supported on both android & ios platforms. So, let’s start building the YouTube Player application in Ionic 5.

Play YouTube Video In Ionic 5 Example

Step1: Create a new Ionic project using the following command

ionic start myApp blank

After that select angular project instead of react.

Move the current directory to the project directory using the following command

cd myApp

Now, Open the newly create the Ionic project in Visual Studio Code using the following command

code .

Step2: Install the YouTube Player Plugin & npm dependency

Ionic 5 YouTube Player app needs to install the YouTube player plugin. So, Let’s install it using the following command.

ionic cordova plugin add cordova-plugin-youtube-video-player

Install npm package using the following command

npm install @ionic-native/youtube-video-player

Step3: Create YouTube API

Now, You need to configure YouTube API Key to play YouTube Video. So, follow the below steps to create a YouTube API.

How to Create YouTube API Key

1 2
Create Project
  • Click on Credential (Left Side Menu) -> Create Credential -> API Key -> Generate API Key
2 1
Generate API Key
  • Click on Library (Left Side Menu)-> Search “youtube data api v3” -> Click Enable
Click on the Library menu to enable YouTube API

Step4: Configure YouTube API Key

Now, You require to configure YouTube API Key in the Ionic application.

Update the config.xml as follows

<preference name="YouTubeDataApiKey" value="[YOUR YOUTUBE API]" />

Step5: Include YoutubeVideoPlayer provider in home.module.ts as follows

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { FormsModule } from '@angular/forms';
import { HomePage } from './';

import { HomePageRoutingModule } from './home-routing.module';
import { YoutubeVideoPlayer } from '@ionic-native/youtube-video-player/ngx';

  imports: [
  declarations: [HomePage],
  providers: [YoutubeVideoPlayer]
export class HomePageModule { }


<ion-header [translucent]="true">

<ion-content [fullscreen]="true">
  <ion-header collapse="condense">
      <ion-title size="large">YouTube Video Player</ion-title>

  <div id="container">
    <ion-button (click)="playVideo()">Play Video</ion-button>

Update as follows

import { Component } from '@angular/core';
import { YoutubeVideoPlayer } from '@ionic-native/youtube-video-player/ngx';

  selector: 'app-home',
  templateUrl: '',
  styleUrls: [''],
export class HomePage {

  constructor(private player: YoutubeVideoPlayer) { }

  playVideo() {

Leave a Comment