Like Us on Facebook

How to play youtube video in Android Application

Hi , In this  tutorial I am going to explain  How to play  youtube  video in any Android application. We are  going to use  youtube  API to play  youtube video within a Android application. Youtube API  required minimum  Android version 4.2 .We can see lots of  android apps playing  youtube video inside the App to tell the app intro . This app will have a single screen with a video playing in it. This article covers basics of YouTube Android API. If you want to build a fully  fledged  youtube  app, please go through  Youtube Android Player API docs provided by  Google.

Read more 
How to play Video streaming Application in Android
How  to parse Json Data in Android Application
How to Create PDF reader Application in Android 
How to create  your  first Android Game


  • JDK 7.0 or Above
  • Android Studio 2.0

Steps to follow:

Step 1: Create a New Android Studio project name YoutubePlayer.

Step 2: Select minimum API level 17 so  that it can run Maximum of  the Android device  available in playstore.

Step 3: Give your layout xml name is activity_main And click finish .

Step 4:  Login to API console

Step 5:  Create a Project -> Go to Services -> Turn on the switch for Google YouTube Data API v3

Step 6:  Goto API Access -> Create new Android Key-> In popup enter one SHA1 certificate fingerprint and package name (separated by a semicolon) per line.

Step 7:  To get SHA1 certificate of your app in Android studio open Terminal enter the following  command keytool -list -v –keystore “path to key” . Then  enter the password of your keystore . Scroll above to get SHA1  fingerprint   key .

Step 8: From here copy SHA1 certificate and also copy package name of your Apps from Android Studio.

Step 9: Now enter these values in the API Console popup in the desired format, you key will be generated.

Step 10: Now Download Android YouTube Player API bundle from here. Unzip this file and follow the steps below to include it in your app:
  1. Copy the jar file from libs folder to the the libs folder of your project.
  2. Right click on your project, File -> Project Structure -> app -> dependencies ->  add File dependencies
  3.  Select YouTubeAndroidPlayerAPI.jar ->Ok
Step 11 : in manifest file add the  internet permission
<uses-permission android:name="android.permission.INTERNET"/>
Step 12: Inside the  activity_main.xml write the following code
<RelativeLayout xmlns:android=""
 android:id ="@+id/play"
 android:text="Hello World!"
 android:id="@+id/textView" />
 android:layout_centerHorizontal="true" />
 android:layout_alignParentTop="true" />

 Step 13 : Inside  write the following code
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 public class MainActivity extends YouTubeBaseActivity{
 Button button;
 private YouTubePlayerView view;
 private YouTubePlayer.OnInitializedListener listener;
 protected void onCreate(Bundle savedInstanceState) {

 view = (YouTubePlayerView)findViewById(

 listener = new YouTubePlayer.OnInitializedListener() {
 public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer  youTubePlayer, boolean b) {
 public void onInitializationFailure(YouTubePlayer.Provider provider,  YouTubeInitializationResult youTubeInitializationResult) {
 button =(Button)findViewById(;
 button.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {

Now compile and test the Application in real device.

Posted By UandBlog

UandBlog is a Global Leading source of Finance, Health, Lifestyle, Technology, Gaming and Programing and other information, it is a fastest growing blog for all , for latest post or information like us on facebook , follow on Twitter, Google+ and Pinterest.

Comments ( 0 )

    Leave a comment..

    Click to login.

    Subscribe Latest Information

    Most Popular Posts

    You May Like Also