com.google.android.youtube.player.YouTubePlayerView Java Examples

The following examples show how to use com.google.android.youtube.player.YouTubePlayerView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomPlayerControlActivity.java    From YouTubePlayerView-Example with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // attaching layout xml
    setContentView(R.layout.activity_custom_player);

    // Initializing YouTube player view
    YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player_view);
    youTubePlayerView.initialize(API_KEY, this);

    //Add play button to explicitly play video in YouTubePlayerView
    mPlayButtonLayout = findViewById(R.id.video_control);
    findViewById(R.id.play_video).setOnClickListener(this);
    findViewById(R.id.pause_video).setOnClickListener(this);

    mPlayTimeTextView = (TextView) findViewById(R.id.play_time);
    mSeekBar = (SeekBar) findViewById(R.id.video_seekbar);
    mSeekBar.setOnSeekBarChangeListener(mVideoSeekBarChangeListener);

    mHandler = new Handler();
}
 
Example #2
Source File: FullscreenDemoActivity.java    From yt-android-player with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.fullscreen_demo);
  baseLayout = (LinearLayout) findViewById(R.id.layout);
  playerView = (YouTubePlayerView) findViewById(R.id.player);
  fullscreenButton = (Button) findViewById(R.id.fullscreen_button);
  checkbox = (CompoundButton) findViewById(R.id.landscape_fullscreen_checkbox);
  otherViews = findViewById(R.id.other_views);

  checkbox.setOnCheckedChangeListener(this);
  // You can use your own button to switch to fullscreen too
  fullscreenButton.setOnClickListener(this);

  playerView.initialize(DeveloperKey.DEVELOPER_KEY, this);

  doLayout();
}
 
Example #3
Source File: PlayerActivity.java    From FlutterYoutube with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        if (getIntent().getBooleanExtra("appBarVisible", false)) {
            setupActionBarColor(actionBar);
        } else {
            actionBar.hide();
        }
    }

    API_KEY = getIntent().getStringExtra("api");
    videoId = getIntent().getStringExtra("videoId");
    goFullScreen = getIntent().getBooleanExtra("fullScreen", false);
    autoPlay = getIntent().getBooleanExtra("autoPlay", false);
    backgroundColor = getIntent().getIntExtra("backgroundColor" , 0xFF1b1b1b);

    final RelativeLayout rootView = (RelativeLayout) findViewById(R.id.root_view);
    rootView.setBackgroundColor(backgroundColor);
    getWindow().getDecorView().setBackgroundColor(backgroundColor);

    youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(API_KEY, this);
}
 
Example #4
Source File: YouTubeActivity.java    From android-inline-youtube-view with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setFullscreen();
    setContentView(R.layout.youtube_player_view);

    YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player);

    String videoId = getVideoId();
    String apiKey = getApiKey();

    /*
     * In case videoId or apiKey is null, throw IllegalStateException as apiKey and videoId is mandatory to run
     * youtube activity.
     */
    $Precondition$Check.checkArgument(!TextUtils.isEmpty(videoId), " videoId cannot be null");
    $Precondition$Check.checkArgument(!TextUtils.isEmpty(apiKey), " apiKey cannot be null");

    /*
     * In case of YouTube Service not available, fallback to WebView implementation.
     */
    if (ServiceUtil.isYouTubeServiceAvailable(this)) {
        youTubePlayerView.initialize(apiKey, this);
    } else {
        String webViewUrl = getWebUrl();
        if (!TextUtils.isEmpty(webViewUrl)) {
            youTubePlayerView.setVisibility(GONE);
            handleWebViewPlayer(videoId, webViewUrl);
        } else {
            Log.d(TAG, "Web Url is Null");
            finish();
        }
    }
}
 
Example #5
Source File: PlayerActivity.java    From search-youtube with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    //method to fill the activity that is launched with  the activity_player.xml layout file
    setContentView(R.layout.activity_player);

    //getting youtube player view object
    playerView = (YouTubePlayerView)findViewById(R.id.player_view);
    
    //initialize method of YouTubePlayerView used to play videos and control video playback
    //arguments are a valid API key that is enabled to use the YouTube Data API v3 service
    //and YouTubePlayer.OnInitializedListener object or the callbacks that will be invoked 
    //when the initialization succeeds or fails
    //as in this case the activity implements OnInitializedListener
    playerView.initialize(YoutubeConnector.KEY, this);

    //initialising various descriptive data in the UI and player
    TextView video_title = (TextView)findViewById(R.id.player_title);
    TextView video_desc = (TextView)findViewById(R.id.player_description);
    TextView video_id = (TextView)findViewById(R.id.player_id);

    //setting text of each View form UI
    //setText method used to change the text shown in the view
    //getIntent method returns the object of current Intent 
    //of which getStringExtra returns the string which was passed while calling the intent
    //by using the name that was associated during call
    video_title.setText(getIntent().getStringExtra("VIDEO_TITLE"));
    video_id.setText("Video ID : "+(getIntent().getStringExtra("VIDEO_ID")));
    video_desc.setText(getIntent().getStringExtra("VIDEO_DESC"));
}
 
Example #6
Source File: MinimalPlayerActivity.java    From YouTubePlayerView-Example with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // attaching layout xml
    setContentView(R.layout.activity_basic_player);

    // Initializing YouTube player view
    YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player_view);
    youTubePlayerView.initialize(API_KEY, this);

}
 
Example #7
Source File: BasicPlayerActivity.java    From YouTubePlayerView-Example with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // attaching layout xml
    setContentView(R.layout.activity_basic_player);

    // Initializing YouTube player view
    YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player_view);
    youTubePlayerView.initialize(API_KEY, this);

}
 
Example #8
Source File: PlayerControlsDemoActivity.java    From yt-android-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.player_controls_demo);

  youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_view);
  stateText = (TextView) findViewById(R.id.state_text);
  videoChooser = (Spinner) findViewById(R.id.video_chooser);
  playButton = (Button) findViewById(R.id.play_button);
  pauseButton = (Button) findViewById(R.id.pause_button);
  skipTo = (EditText) findViewById(R.id.skip_to_text);
  eventLog = (TextView) findViewById(R.id.event_log);

  styleRadioGroup = (RadioGroup) findViewById(R.id.style_radio_group);
  ((RadioButton) findViewById(R.id.style_default)).setOnCheckedChangeListener(this);
  ((RadioButton) findViewById(R.id.style_minimal)).setOnCheckedChangeListener(this);
  ((RadioButton) findViewById(R.id.style_chromeless)).setOnCheckedChangeListener(this);
  logString = new StringBuilder();

  videoAdapter = new ArrayAdapter<ListEntry>(this, android.R.layout.simple_spinner_item, ENTRIES);
  videoAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  videoChooser.setOnItemSelectedListener(this);
  videoChooser.setAdapter(videoAdapter);

  playButton.setOnClickListener(this);
  pauseButton.setOnClickListener(this);
  skipTo.setOnEditorActionListener(this);

  youTubePlayerView.initialize(DeveloperKey.DEVELOPER_KEY, this);

  playlistEventListener = new MyPlaylistEventListener();
  playerStateChangeListener = new MyPlayerStateChangeListener();
  playbackEventListener = new MyPlaybackEventListener();

  setControlsEnabled(false);
}
 
Example #9
Source File: PlayerViewDemoActivity.java    From yt-android-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.playerview_demo);

  YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
  youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
}
 
Example #10
Source File: PlayerActivity.java    From RxTube with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  youtubeDevKey = getIntent().getStringExtra(YOUTUBE_DEV_KEY_EXTRA);

  if (TextUtils.isEmpty(youtubeDevKey)) {
    throw new IllegalStateException("You need to pass a valid youtube_dev_key");
  }

  videoId = getIntent().getStringExtra(VIDEO_ID_EXTRA);

  if (TextUtils.isEmpty(videoId)) {
    throw new IllegalStateException("You need to pass a valid video_id");
  }

  setContentView(R.layout.youtube_player_view_container);

  youtubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player_view);

  initializeVideo();
}
 
Example #11
Source File: PlayerViewDemoActivity.java    From yt-android-player with Apache License 2.0 4 votes vote down vote up
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
  return (YouTubePlayerView) findViewById(R.id.youtube_view);
}