quinta-feira, 24 de julho de 2014

YouTubePlayerView Example in Android using YouTube API

In this tutorial we’ll see how to use YouTube Player API in android. YouTube player API provided and embedded view that supports with various playback controls.

1. Downloading YouTube Player API

Before you start writing some code, you’ll have to first download the YouTube Android Player API. Once downloaded import the jar into your project lib folder and add the jar to your build path.
Download YouTube Player API here
YouTube Android Player API

2. Register your app in Google developer console

  1. Before you start using the Youtube player API for android, you have to register your application with Google developer console and get and API key, The API key is a unique value for your application. Do not disclose this to others.
  2. Visit Google APIs Console and login with your Google account and create a new project
  3. Once your project is created, got to API’s and enable “YouTube data API V3”
  4. And then Select “API Access” in your API Console. You’ll find API key. This API key will be used to access YouTube Android Player APIs.
YouTube Android Player API2

 

3. Create a new Android Application project

Now you are ready to create Android project to play YouTube videos using YouTube player API. You may use IDE of your choice, here I am using Eclipse.
You need INTERNET permission to play video over internet. Add below permission in your application AndroidManifest.xml file.

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

 

4. Define your activity layout

In this example, we will create an simple layout that uses YouTubePlayerView inside an LinearLayout.


 

5. Initialize YouTubePlayerView in your Activity

Initializing YouTube player view by calling initialize methood. Once the initialize is successful, you will get the onInitializationSuccess() callback with YouTubePlayer instance. You can add additional listeners to handle the playback control events.



 

6. Output
YouTube Android Player API Example - Javatechig

7. References

https://developers.google.com/youtube/

Nenhum comentário:

Postar um comentário