Setting Up an API Project

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.

  1. Eclipse
  2. IntelliJ

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.

  1. Install the ADT plugin for the Eclipse IDE. You must install version 20 or greater of the plugin.

  2. Download the latest version of the YouTube Android Player API and unzip the downloaded file.

  3. In Eclipse, create a new project for the sample applications distributed with the YouTube Android Player API code.

    1. From the File menu, select New and from the submenu, choose Project.
    2. In the Select a wizard pane, choose Android -> Android Project from Existing Code.
    3. To import the project, select the root directory by browsing to the directory where you unzipped the downloaded YouTube Android Player API file.
    4. Eclipse should search the selected directory and locate the YouTubeAPIDemoActivity project. Select that project and click Finish 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.

  4. Open the DeveloperKey.java file in the YouTubeAndroidAPIDemo package (YouTubeAndroidAPIDemo/src/com/examples/youtubeapidemo/DeveloperKey.java) and replace null 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.

  5. 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.

    1. Connect an Android device running version 4.2.16 or later of the YouTube app.
    2. From the Run menu, select Run Configurations.
    3. In the Target pane, make sure that your settings will launch the sample applications on your connected Android device.
    4. Click Run to run the samples on your connected device.

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.

  1. Download the Android SDK.

  2. Configure the Android SDK at the global (IDE) level in IntelliJ.

  3. Download the latest version of the YouTube Android Player API and unzip the downloaded file in the location where IntelliJ will access it.

  4. Open IntelliJ.

    1. From the File menu, select Import Project. When prompted to select the file or directory to import, browse to the sample directory in the unzipped file contents.
    2. Choose to create the project from existing sources.
    3. Set the name and project location for the project. (The project location should specify the sample directory.)
    4. Choose to add all of the source files located for the project to the project roots.
    5. Review the libraries found for the project and proceed to the next step.
    6. Review the module structure found for the project and proceed to the next step.
    7. Choose the Android 4.2 (or later) platform SDK as the project SDK.
    8. Review the frameworks detected for the project and finish importing the project.

  5. Open the DeveloperKey.java file in the com.examples.youtubeapidemo package (sample/src/com/examples/youtubeapidemo/DeveloperKey.java) and replace null 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.

  6. From the Build menu, select Make project to build the project.

  7. 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.

    1. Connect an Android device running version 4.2.16 or later of the YouTube app.
    2. From the Run menu, select Run.
    3. Edit the configurations for running the sample applications.
    4. In the General tab, under the Target Device section, select USB device.
    5. Click Run to run the samples on your connected device.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.