Hello Readers,
This post is about YouTube Android player API plugin Which allows play videos in YouTube native player.
First of all, we need to register our Cordova Android apps in Google Developers Console and then enable the YouTube API. After registration, we get an API key save it for further use. To register your app Click Here.
Now, We need to install a plugin for access the YouTube Native player API through CLI:
$ npm install remcob00-cordova-youtube-android-player-api
Or Install the plugin manually
- Download the plugin latest release which contains plugin information. For download Click Here unzip the folder then copy and paste in the plugin folder of your app.
- Download the YouTube Android Player API library from Google Developers Console.
- After download unzip the file and copy libs/YouTubeAndroidPlayerApi.jar file and paste src/android folder in a plugin (Which is in plugin folder done in step one).
- Now run the following command to install plugin:
cordova plugin add / path from the plugin folder
Now we are done with the registration of app in Google Developers Console and installation of a plugin in a project.
YouTube Android player requires the API key which we copied during app registration on Google Developers Console. We need to set the API before we can play the video.
window.youtube.init("API key");
Play video :
To play a video we need a YouTube id of if we want to play more than one video then we need a playlist id.
Example:
window.youtube.playVideo("YouTube video ID");
In the above code, we can play a single video. We can add start time, autoplay parameters in the method.
window.youtube.playPlaylist("YouTube playlist ID");
In the above code can play a playlist.
For more details click here.
Hope this will help you... :)
0 Comment(s)