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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates an intent that will start a new standalone player activity that plays the videos in a
playlist.
| |||||||||||
Creates an intent that will start a new standalone player activity that plays the videos in a
playlist.
| |||||||||||
Creates an intent that will start a new standalone player activity that plays a single
video.
| |||||||||||
Creates an intent that will start a new standalone player activity that plays a single
YouTube video.
| |||||||||||
Creates an intent that will start a new standalone player activity that plays a list of
videos.
| |||||||||||
Creates an intent that will start a new standalone player activity that plays a list of
videos.
| |||||||||||
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 . |
Inherited methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public methods
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.
Calling this method is the same as calling
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 Developers Console. |
playlistId | The YouTube playlist id to be played. |
Returns
- An intent which will start a
YouTubeStandalonePlayer
with the given settings.
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 Developers 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
- An intent which will start a
YouTubeStandalonePlayer
with the given settings.
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 Developers 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
- An intent which will start a
YouTubeStandalonePlayer
with the given settings.
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.
Calling this method is the same as calling
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 Developers Console. |
videoId | The id of the video to be played. |
Returns
- An intent which will start a
YouTubeStandalonePlayer
with the given settings.
public static Intent createVideosIntent (Activity activity, String developerKey, List<String> videoIds)
Creates an intent that will start a new standalone player activity that plays a list of videos.
Calling this method is the same as calling
createVideosIntent(activity, developerKey, videoIds, 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 Developers Console. |
videoIds | The list of videos to be played. |
Returns
- An intent which will start a
YouTubeStandalonePlayer
with the given settings.
public static Intent createVideosIntent (Activity activity, String developerKey, List<String> videoIds, int startIndex, int timeMillis, boolean autoplay, boolean lightboxMode)
Creates an intent that will start a new standalone player activity that plays a list of videos.
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 Developers Console. |
videoIds | The list of videos 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
- An intent which will start a
YouTubeStandalonePlayer
with the given settings.
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 eitherSUCCESS
if the standalone player started successfully, or provides details of the error which prevented the standalone player from starting.