Tutorial- How to play YouTube video in Android app

0 307

Play YouTube video in Android app

It is very simple and easy to Play YouTube video in Android app. To play videos in Android Application we require YouTube API. In order to use YouTube API, you require minimum Android version 4.2. We can also build a complete YouTube Application using the YouTube Android Player API.

YouTube Android Player API

The YouTube Android Player API enables you to include video playback functionality in your Android Applications. The API describes ways for loading and playing YouTube videos and also for modifying and managing the video playback experience. For example:

  • Play video
  • Pause Video
  • Seek to a specific point in the recently loaded video

Today I will describe steps to build a simple App having the single screen with a playing video in it. We will cover the crucial part of YouTube Android API.

Follow these steps

Before following these steps you must have JDK 7.0 or above and Android Studio 2.0 installed on your device or PC.

  • The first step is to create a New Project in Android Studio and name it .
  • The minimum API level should be set to 17 so that it can run most of the Android device in Playstore.
  • Name your layout xml as activity_main and press finish.
  • Now login to the API console.
  • Then create a Project select Go to services Enable the switch for Google YouTube Data API v3.
  • Now Go to API Access and click on Create new Android Key. When the popup appears to enter one SHA1 certificate fingerprint and the package name( separated by 😉 for each line.
  • In Android Studio to get the SHA1 certificate of your App, you have to open Terminal and enter the following command keytool –list-v-keystore “path to key”. Now enter the password for your keystore. You can scroll above to get SHA1 fingerprint key.


  • Next you have to copy the SHA1 certificate from here and also the package name of your Apps from Android Studio.
  • In order to generate a key, enter these values in API Console popup in the desired format.
  • Now you have to download the Android YouTube Player API bundle from here. After downloading it unzip this file and follow the instructions given below:
  • From libs folder copy the jar file to the libs folder of your project.
  • next step go to build.gradle and add dependencies like this compile files(‘libs/YouTubeAndroidPlayerApi.jar’)

Add the internet permission in the manifest file.

Write the following code inside the activity_main.xml.

Write the following code inside the MainActivity.java



Leave A Reply

Your email address will not be published.