Embed Video in your Android Application Using YouTube Android Player API v1.2.1

With YouTube Android Player API, you can embed videos and playlists into your application. User gets playback and controlling experience much similar Official YouTube Android Application. User can control loading and playing of embedded YouTube video. Playing, cueing and loading can be controlled programmatically as well. Event listeners api’s with support of events like open fullscreen or player loading etc gives you complete control that you would desire of.


YouTube Android Player Api client library is dependent on YouTube Application, it interacts with services part of YouTube application for video playback.

 

[su_button url=”https://github.com/androidsrc/YouTubeApiIntegration” target=”blank” style=”stroked” background=”#51d461" color=”#ffffff” size=”6" center=”yes” radius=”0" icon=”icon: arrow-circle-o-down”] Download Source Code[/su_b[/su_button]p> 

[su_ca[su_carousel source=”media: 467,466,465" link=”lightbox” width=”900" height=”500" items=”1" title=”no” mousewheel=”no”]p> 

Step 1. Registering application with Google Developers Console

1.1 Go to Google Developers Console, Create a new project if none exists or select an existing project.

1.2 Navigate to APIs & auth -> APIs in left sidebar, browse for YouTube Data API v3 and turn on its status accepting terms of services.

 

YouTubePlayerAPI_Step1

 

1.3 Generate SHA1 fingerprint using java keytool utility

For getting API key, we need to generate SHA-1 fingerprint using java keytool. Open your command prompt and execute the below mentioned command to generate SHA-1 fingerprint. If keytool is not recognized, you can find it in bin directory of installed jre. In my case C:\Program Files\Java\jre7\bin.

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

 

YouTubePlayerAPI_SHA1_keytool

 

From output note down SHA1 output, “FD:0E:04:E9:99:28:B9:3D:E7:AC:75:AF:6E:2B:F6:E7:CD:EE:CA:96″ in my case.

 

1.4 Generate API Key

Navigate to APIs & auth -> credentials in left sidebar, select Create New Key and opt for Android key.

 

YouTubePlayerAPI_AndroidKey

 

Enter your SHA1 fingerprint and application package name sperated by semi-colon(;) and select create. It will generate API key for your application. Note down API key for later usage. API Key generated in my case is AIzaSyBcTwxVG7eYC314bzw1D28XwFi5xe6DT7k.

 

YouTubePlayerAPI_AndroidKeyStep3

Step 2. Developing Sample Application using YouTube Android Player API

2.1 Create new Android Application Project in Eclipse with package name.

 

YouTubeAPI_Demo

 

2.2 Download latest version 1.2.1 of YouTube Android Player API and extract downloaded file.

2.3 From extracted files, copy YouTubeAndroidPlayerApi.jar from libs folder to add it to libs folder of your android application.

2.4 Preparing Application Manifest File

Add android.permission.INTERNET permission to access Internet. We will have just one activity in our application which will embed YouTube video.

You may also like...

9 Responses

  1. Heidi says:

    Hello Author. I have followed all your instructions. There are no errors, but when I run it on my device, it force closes. Any idea why this happens. Thanks.

  2. KocuOgebz says:

    Hi, i try your code. but when i run show message “Get YouTube App” This app won’t run without the youtube App, which is missing form your device. Any idea? thanks

  3. sam says:

    Hello i want to embed my video in app which can play offline so kindly guide me thanks!
    Ex When user will start app then video will start playing without internet. My video is not on youtube.

  4. Humayoon says:

    hy every one I have embed video link of dailymotion i want to get m3u8 link from embed link not using html parsing kindly tell me the other way

  5. adamzfun says:

    So how about if you want this to read a youtube playlist from an xml file? Can you embed live channels from youtube?

  1. March 29, 2016

    […] Embed Video in your Android Application Using YouTube Android Player API v1.2.1 […]

Leave a Reply

Your email address will not be published. Required fields are marked *