Android Open Source - Android_Youtube_Sampler One Video






From Project

Back to project page Android_Youtube_Sampler.

License

The source code is released under:

GNU General Public License

If you think the Android project Android_Youtube_Sampler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.pgmacdesign.youtubebasics;
/*  ww  w  .  j  a v a  2s  .c  o  m*/
import android.os.Bundle;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayerSupportFragment;
import com.google.android.youtube.player.YouTubePlayerView;

//Plays the passed in video once inflated
public class OneVideo extends YouTubePlayerSupportFragment {

  private String currentVideoID = "video_id";
  private YouTubePlayer activePlayer;

  public static OneVideo newInstance(String url) {
    //Object of video fragment format
    OneVideo playerYouTubeFrag = new OneVideo();

    //Bundle to add details from the URL passed in
    Bundle bundle = new Bundle();
    bundle.putString("url", url);

    //Set the arguments into the bundle and then initiate it
    playerYouTubeFrag.setArguments(bundle);
    playerYouTubeFrag.init();

    return playerYouTubeFrag;
  }

  protected YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerView) getActivity().findViewById(R.id.youtube_view);
  }


  private void init() {
    initialize(DeveloperKey.API_KEY, new OnInitializedListener() {

      @Override
      public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
        activePlayer = player;
        activePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
        if (!wasRestored) {
          activePlayer.loadVideo(getArguments().getString("url"), 0);

        }
      }

      @Override
      public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
      }
    });
  }

  public void onYouTubeVideoPaused() {
    activePlayer.pause();
  }
}




Java Source Code List

com.pgmacdesign.youtubebasics.DeveloperKey.java
com.pgmacdesign.youtubebasics.InitialFragment.java
com.pgmacdesign.youtubebasics.MainActivity.java
com.pgmacdesign.youtubebasics.NavigationDrawerFragment.java
com.pgmacdesign.youtubebasics.OneVideo.java
com.pgmacdesign.youtubebasics.PlaylistVideo.java
com.pgmacdesign.youtubebasics.Splash.java