Friday, 9 December 2016

Tutorial Watch Youtube's Video From Own Android Application

Today i going to share a tutorial integrated with Youtube. Exactly how to display youtube video into your own android application.


We using Youtube Android API and must be activated. Then we create the credentials. For more information please go through Youtube Android Player API.

See also how to login using facebook


ACTIVATED THE YOUTUBE API KEY AND GET THE CREDENTIAL


1. Go to Developer Console
2. Create New Project or use an existing project

Create project

3. If you choose to create new project, then fill your project name

Fill the project name

4. Take a look to API Youtube, and click Youtube Data API


Youtube data API

5. Enable the Youtube Data API

Enable

6. Create credential by clicked the button Create Credential


Create the credential

7. Fill the credential field

Credential field

9. Here it is, the credentials

The credentials


That's all the steps how to enable the Youtube API and create the credentials on your project. Now time to start the Android project.



CREATE ANDROID STUDIO PROJECT



Download the latest version of Youtube Android Player API, HERE. Extract the zip file and find the YoutubeAndroidPlayerApi.jar.

Place the YoutubeAndroidPlayerApi.jar in your project's libs folder. Right click on the jar, choose menu Add As Library.

Create one layout :

  1. activity_main.xml
Create two java classes :
  1. Constant.java
  2. MainActivity.java
After you creating all layout and java classes, now modify these layout and java classes one by one. 

Modify your activity_main.xml, paste the following code :

Modify your Constant.java, define your YOUTUBE API KEY and the YOUTUBE VIDEO ID here. You can find out the YOUTUBE VIDEO ID on the URL.

Example the URL is : https://www.youtube.com/watch?v=WhRaCA9bC9kWhRaCA9bC9k is the video ID.

take a look at the following code :

Last, modify your MainActivity.java, MainActivity.java has to extends YoutubeBaseActivity. Paste the following code :

Don't forget to add INTERNET permission in your AndroidManifest.xml :

<uses-permission android:name="android.permission.INTERNET"/>

DOWNLOAD THE PROJECT HERE : GITHUB LINK


EmoticonEmoticon