Android app has different types of presenting data to end user and video is one of its kind so in this tutorial we can help you out with integrating youtube video into your app.

 

Before going any further into tutorial lets get a api key from google console api  Google Api Key

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Create a credential using your SHA1 Algorithm

 

then

API key is generated if required you can restrict your api key depending upon your usage level.Copy the api key for further usage in integrating youtube videos.

 

Add youtube library to your android studio projects

Youtube Android Player API — Download

 

add it to libs folder of your project and integrate to

build.gradle(Module: app)

 

Let’s start coding

 

activity_adview

add YouTubePlayerView

 

 

Config

Configure youtube player with the api key which is generated in above process and also youtube video which you want to play

Get video code from Youtube Link || Youtube video code

 

YoutubeActivity.java

Now initialize youtube player, EventListener & StateChangeListener

 

 

then

 

if initialization failed

 

and when succeeded

 

Using EventListener we can track video whether video is being played, paused, stopped, buffering

 

 

and using StateChangeListener we can know whether video is loaded, any error occurred or whether the ad started in between the video and most importantly whether the video is ended.

 

 

 

Manifest

Add internet permission to manifest file

 

 

Share and like this tutorial if you like it.

Show Buttons
Hide Buttons
Read previous post:
Android Sending SMS || Tutorial on how to send text message within app

Close