This page explains how to set up Eclipse or IntelliJ to run the sample applications for the YouTube Android Player API.
Both sets of instructions require you to enter a developer key that is associated with your usage of the API. You can obtain a developer key by registering your application and obtaining an Android API key in the Google APIs console.
Important: When registering your application, make sure that the YouTube Data API v3 service is added for your project. The YouTube Android Player API depends on the Data API to retrieve YouTube content.
In addition, the sample applications document briefly describes the applications that ship with the API library, and the Android Dev Guide explains how to debug apps on a connected Android device.
Eclipse
The following steps explain how to set up your Eclipse environment to build and run the sample projects distributed with the API. Note that the instructions explain the steps for using Eclipse SDK version 3.8.0.
-
Install the ADT plugin for the Eclipse IDE. You must install version 20 or greater of the plugin.
-
Download the latest version of the YouTube Android Player API and unzip the downloaded file.
-
In Eclipse, create a new project for the sample applications distributed with the YouTube Android Player API code.
- From the
File
menu, selectNew
and from the submenu, chooseProject
. - In the
Select a wizard
pane, chooseAndroid -> Android Project from Existing Code
. - To import the project, select the root directory by browsing to the directory where you unzipped the downloaded YouTube Android Player API file.
- Eclipse should search the selected directory and locate the
YouTubeAPIDemoActivity
project. Select that project and clickFinish
to complete the import.
When creating a new project, you need to import the client library
YouTubeAndroidPlayerApi.jar
file to your<project_root>/libs
directory so that the library will be included in your build path. You can also manually add the.jar
file to your build path. - From the
-
Open the
DeveloperKey.java
file in theYouTubeAndroidAPIDemo
package (YouTubeAndroidAPIDemo/src/com/examples/youtubeapidemo/DeveloperKey.java
) and replacenull
with a valid YouTube developer key in the following line:public static final String DEVELOPER_KEY = null;
If you do not set the developer key, the samples will throw a
java.lang.NullPointerException
and close when you attempt to run them. -
Run the samples on a connected Android device. Note that the emulator may not run the required version of the YouTube app, which would cause the samples to fail to run.
- Connect an Android device running version
4.2.16
or later of the YouTube app. - From the
Run
menu, selectRun Configurations
. - In the
Target
pane, make sure that your settings will launch the sample applications on your connected Android device. - Click
Run
to run the samples on your connected device.
- Connect an Android device running version
IntelliJ
The following steps explain how to set up your IntelliJ environment to build and run the sample projects distributed with the API. Note that the instructions explain the steps for using the IntelliJ IDEA 12.0 community edition.
-
Configure the Android SDK at the global (IDE) level in IntelliJ.
-
Download the latest version of the YouTube Android Player API and unzip the downloaded file in the location where IntelliJ will access it.
-
Open IntelliJ.
- From the
File
menu, selectImport Project
. When prompted to select the file or directory to import, browse to thesample
directory in the unzipped file contents. - Choose to create the project from existing sources.
- Set the name and project location for the project. (The project location should specify the
sample
directory.) - Choose to add all of the source files located for the project to the project roots.
- Review the libraries found for the project and proceed to the next step.
- Review the module structure found for the project and proceed to the next step.
- Choose the Android 4.2 (or later) platform SDK as the project SDK.
- Review the frameworks detected for the project and finish importing the project.
- From the
-
Open the
DeveloperKey.java
file in thecom.examples.youtubeapidemo
package (sample/src/com/examples/youtubeapidemo/DeveloperKey.java
) and replacenull
with a valid YouTube developer key in the following line:public static final String DEVELOPER_KEY = null;
If you do not set the developer key, the samples will throw a
java.lang.NullPointerException
and close when you attempt to run them. -
From the
Build
menu, selectMake project
to build the project. -
Run the samples on a connected Android device. Note that the emulator may not run the required version of the YouTube app, which would cause the samples to fail to run.
- Connect an Android device running version
4.2.16
or later of the YouTube app. - From the
Run
menu, selectRun
. - Edit the configurations for running the sample applications.
- In the
General
tab, under theTarget Device
section, selectUSB device
. - Click
Run
to run the samples on your connected device.
- Connect an Android device running version