YouTube

YouTubeStandalonePlayer

public final class
YouTubeStandalonePlayer
extends Object
java.lang.Object
   ↳ com.google.android.youtube.player.YouTubeStandalonePlayer

Overview

This class creates intents that will play YouTube videos in a standalone player activity.

Using this class is a very easy way to play YouTube videos within your application. Starting a video is as simple as running the following code within your activity:

 Intent intent = YouTubeStandalonePlayer.createVideoIntent(context, YOUR_DEVELOPER_KEY, VIDEO_ID);
 startActivity(intent);
 

Summary

Public methods
static Intent createPlaylistIntent(Activity activity, String developerKey, String playlistId, int startIndex, int timeMillis, boolean autoplay, boolean lightboxMode)
Creates an intent that will start a new standalone player activity that plays the videos in a playlist.
static Intent createPlaylistIntent(Activity activity, String developerKey, String playlistId)
Creates an intent that will start a new standalone player activity that plays the videos in a playlist.
static Intent createVideoIntent(Activity activity, String developerKey, String videoId)
Creates an intent that will start a new standalone player activity that plays a single YouTube video.
static Intent createVideoIntent(Activity activity, String developerKey, String videoId, int timeMillis, boolean autoplay, boolean lightboxMode)
Creates an intent that will start a new standalone player activity that plays a single video.
static YouTubeInitializationResult getReturnedInitializationResult(Intent data)
If you start the YouTubeStandalonePlayer activity with startActivityForResult, you can use this method to transform the data intent passed back in onActivityResult into a YouTubeInitializationResult.
[Expand]
Inherited methods
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait()
final void wait(long arg0, int arg1)
final void wait(long arg0)

Public methods

public static Intent createPlaylistIntent (Activity activity, String developerKey, String playlistId, int startIndex, int timeMillis, boolean autoplay, boolean lightboxMode)

Creates an intent that will start a new standalone player activity that plays the videos in a playlist.

Parameters
activity The calling activity from which the standalone player will be started.
developerKey A valid API key which is enabled to use the YouTube Data API v3 service. To generate a new key, visit the Google APIs Console.
playlistId The YouTube playlist id to be played.
startIndex The index of the video to play first.
timeMillis The time, in milliseconds, where playback should start in the first video played.
autoplay true to have the video start playback as soon as the standalone player loads, false to cue the video.
lightboxMode true to have the video play in a dialog view above your current Activity, false to have the video play fullscreen.
Returns

public static Intent createPlaylistIntent (Activity activity, String developerKey, String playlistId)

Creates an intent that will start a new standalone player activity that plays the videos in a playlist.

Equivalent to createPlaylistIntent(activity, developerKey, playlistId, 0, 0, false, false).

Parameters
activity The calling activity from which the standalone player will be started.
developerKey A valid API key which is enabled to use the YouTube Data API v3 service. To generate a new key, visit the Google APIs Console.
playlistId The YouTube playlist id to be played.
Returns

public static Intent createVideoIntent (Activity activity, String developerKey, String videoId)

Creates an intent that will start a new standalone player activity that plays a single YouTube video.

Equivalent to createVideoIntent(activity, developerKey, videoId, 0, false, false).

Parameters
activity The calling activity from which the standalone player will be started.
developerKey A valid API key which is enabled to use the YouTube Data API v3 service. To generate a new key, visit the Google APIs Console.
videoId The id of the video to be played.
Returns

public static Intent createVideoIntent (Activity activity, String developerKey, String videoId, int timeMillis, boolean autoplay, boolean lightboxMode)

Creates an intent that will start a new standalone player activity that plays a single video.

Parameters
activity The calling activity from which the standalone player will be started.
developerKey A valid API key which is enabled to use the YouTube Data API v3 service. To generate a new key, visit the Google APIs Console.
videoId The id of the video to be played.
timeMillis The time, in milliseconds, where playback should start in the video.
autoplay true to have the video start playback as soon as the standalone player loads, false to cue the video.
lightboxMode true to have the video play in a dialog view above your current Activity, false to have the video play fullscreen.
Returns

public static YouTubeInitializationResult getReturnedInitializationResult (Intent data)

If you start the YouTubeStandalonePlayer activity with startActivityForResult, you can use this method to transform the data intent passed back in onActivityResult into a YouTubeInitializationResult. This is useful in debugging problems encountered when starting a YouTubeStandalonePlayer.

Parameters
data The data intent which was passed back in onActivityResult after calling startActivityForResult with an intent created using this class.
Returns
  • A YouTubeInitializationResult which is either SUCCESS if the standalone player started successfully, or provides details of the error which prevented the standalone player from starting.

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.