Click here to see your recently viewed pages and most viewed pages.
Hide

YouTubePlayerView

public final class
YouTubePlayerView
extends ViewGroup
implements YouTubePlayer.Provider
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ com.google.android.youtube.player.YouTubePlayerView

Overview

A view for displaying YouTube videos. Using this View directly is an alternative to using the YouTubePlayerFragment. If you choose to use this view directly, your activity needs to extend YouTubeBaseActivity.

To get started, place this view in your view hierarchy and call initialize(String, OnInitializedListener) to create a YouTubePlayer which you can use to load videos into this View.

This view will save and restore the state of the YouTubePlayer associated with the view as part of the onSaveInstanceState/onRestoreInstanceState flow. See the documentation for YouTubePlayer for more details.

It is encouraged that you handle configuration changes caused by orientation in your activity manually, to avoid recreating this view every time the configuration changes. For the best user experience, you should also manually handle the fullscreen event by changing the layout of your activity. See FULLSCREEN_FLAG_CUSTOM_LAYOUT for more details.

Note that while videos are playing, this View has a minimum size of 200x110 dp. If you make the view any smaller, videos will automatically stop playing. Also, it is not permitted to overlay the view with other views while a video is playing.

This view does not support padding. To achieve the same effect, wrap the view in another ViewGroup or give it margins.

Summary

Inherited Constants
Inherited Fields
Public constructors
YouTubePlayerView(Context context)
Create a YouTubePlayerView.
YouTubePlayerView(Context context, AttributeSet attrs)
Create a YouTubePlayerView.
YouTubePlayerView(Context context, AttributeSet attrs, int defStyle)
Create a YouTubePlayerView.
Public methods
void initialize(String developerKey, YouTubePlayer.OnInitializedListener onInitializedListener)
Initialize a YouTubePlayer which can be used to play videos and control video playback.
void setPadding(int left, int top, int right, int bottom)
Padding is not supported by this view.
Inherited methods

Public constructors

public YouTubePlayerView (Context context)

Create a YouTubePlayerView. Use this constructor to construct a YouTubePlayerView programmatically inside a YouTubeBaseActivity.

Parameters
context The context this view should use. This must be a YouTubeBaseActivity.

public YouTubePlayerView (Context context, AttributeSet attrs)

Create a YouTubePlayerView. This constructor is for use by a LayoutInflater when the view is inflated from XML. This version uses a default style of 0.

Parameters
context The context this view should use. This must be a YouTubeBaseActivity.
attrs The attributes of the XML tag that is inflating the view.

public YouTubePlayerView (Context context, AttributeSet attrs, int defStyle)

Create a YouTubePlayerView. This constructor is for use by a LayoutInflater when the view is inflated from XML.

Parameters
context The context this view should use. This must be a YouTubeBaseActivity.
attrs The attributes of the XML tag that is inflating the view.
defStyle The default style to apply to this view.

Public methods

public void initialize (String developerKey, YouTubePlayer.OnInitializedListener onInitializedListener)

Initialize a YouTubePlayer which can be used to play videos and control video playback. One of the callbacks in listener will be invoked when the initialization succeeds or fails.

Parameters
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.
onInitializedListener The callbacks that will be invoked when the initialization succeeds or fails.

public void setPadding (int left, int top, int right, int bottom)

Padding is not supported by this view. This method is a no-op.