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
Filemenu, selectNewand from the submenu, chooseProject. - In the
Select a wizardpane, 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
YouTubeAPIDemoActivityproject. Select that project and clickFinishto complete the import.
When creating a new project, you need to import the client library
YouTubeAndroidPlayerApi.jarfile to your<project_root>/libsdirectory so that the library will be included in your build path. You can also manually add the.jarfile to your build path. - From the
-
Open the
DeveloperKey.javafile in theYouTubeAndroidAPIDemopackage (YouTubeAndroidAPIDemo/src/com/examples/youtubeapidemo/DeveloperKey.java) and replacenullwith 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.NullPointerExceptionand 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.16or later of the YouTube app. - From the
Runmenu, selectRun Configurations. - In the
Targetpane, make sure that your settings will launch the sample applications on your connected Android device. - Click
Runto 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
Filemenu, selectImport Project. When prompted to select the file or directory to import, browse to thesampledirectory 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
sampledirectory.) - 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.javafile in thecom.examples.youtubeapidemopackage (sample/src/com/examples/youtubeapidemo/DeveloperKey.java) and replacenullwith 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.NullPointerExceptionand close when you attempt to run them. -
From the
Buildmenu, selectMake projectto 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.16or later of the YouTube app. - From the
Runmenu, selectRun. - Edit the configurations for running the sample applications.
- In the
Generaltab, under theTarget Devicesection, selectUSB device. - Click
Runto run the samples on your connected device.
- Connect an Android device running version