Java Code Examples for com.google.android.youtube.player.YouTubePlayer#Provider

The following examples show how to use com.google.android.youtube.player.YouTubePlayer#Provider . 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: YoutubeOverlayFragment.java    From AndroidYoutubeOverlay with MIT License 6 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer player, boolean restored) {
    LogHelper.logMessage("onInitializationSuccess: " + restored + " videoId: " + videoId);
    this.player = player;
    player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
    player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
    player.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {

        @Override
        public void onFullscreen(boolean fullscreen) {
            YoutubeOverlayFragment.this.fullscreen = fullscreen;
        }
    });
    if (!restored && videoId != null) {
        player.loadVideo(videoId);
    }
}
 
Example 2
Source File: YouTubePlayerController.java    From react-native-youtube with MIT License 6 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
    if (!wasRestored) {
        mYouTubePlayer = youTubePlayer;
        mYouTubePlayer.setPlayerStateChangeListener(this);
        mYouTubePlayer.setPlaybackEventListener(this);
        mYouTubePlayer.setOnFullscreenListener(this);
        updateFullscreen();
        updateShowFullscreenButton();
        updateControls();

        if (mVideoId != null) loadVideo();
        else if (!mVideoIds.isEmpty()) loadVideos();
        else if (mPlaylistId != null) loadPlaylist();
    }
}
 
Example 3
Source File: FullscreenDemoActivity.java    From yt-android-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
    boolean wasRestored) {
  this.player = player;
  setControlsEnabled();
  // Specify that we want to handle fullscreen behavior ourselves.
  player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
  player.setOnFullscreenListener(this);
  if (!wasRestored) {
    player.cueVideo("avP5d16wEp0");
  }
}
 
Example 4
Source File: FragmentDemoActivity.java    From yt-android-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
    boolean wasRestored) {
  if (!wasRestored) {
    player.cueVideo("nCgQDjiotG0");
  }
}
 
Example 5
Source File: ActionBarDemoActivity.java    From yt-android-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
    boolean wasRestored) {
  player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
  player.setOnFullscreenListener(this);

  if (!wasRestored) {
    player.cueVideo("9c6W4CCU9M4");
  }
}
 
Example 6
Source File: Fragment3.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    if (youTubeInitializationResult.isUserRecoverableError()) {
        youTubeInitializationResult.getErrorDialog(getActivity(), RECOVERY_DIALOG_REQUEST).show();
    } else {
        //Handle the failure
        Toast.makeText(getActivity(), "onInitializationFailure", Toast.LENGTH_LONG).show();
    }
}
 
Example 7
Source File: Fragment2.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    if (youTubeInitializationResult.isUserRecoverableError()) {
        youTubeInitializationResult.getErrorDialog(getActivity(), RECOVERY_DIALOG_REQUEST).show();
    } else {
        //Handle the failure
        Toast.makeText(getActivity(), "onInitializationFailure", Toast.LENGTH_LONG).show();
    }
}
 
Example 8
Source File: YouTubeFailureRecoveryActivity.java    From yt-android-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
    YouTubeInitializationResult errorReason) {
  if (errorReason.isUserRecoverableError()) {
    errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
  } else {
    String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());
    Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
  }
}
 
Example 9
Source File: VideoWallDemoActivity.java    From yt-android-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onInitializationFailure(
    YouTubePlayer.Provider provider, YouTubeInitializationResult errorReason) {
  if (errorReason.isUserRecoverableError()) {
    if (errorDialog == null || !errorDialog.isShowing()) {
      errorDialog = errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST);
      errorDialog.show();
    }
  } else {
    String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());
    Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
  }
}
 
Example 10
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);
}
 
Example 11
Source File: FullscreenDemoActivity.java    From yt-android-player with Apache License 2.0 4 votes vote down vote up
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
  return playerView;
}
 
Example 12
Source File: YouTubeActivity.java    From android-inline-youtube-view with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer player, boolean restored) {
    youTubePlayer = player;
    youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
    youTubePlayer.setShowFullscreenButton(true);
    youTubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);
    youTubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);

    youTubePlayer.setPlaybackEventListener(new YouTubePlayer.PlaybackEventListener() {
        @Override
        public void onPlaying() {
            if (youTubePlayer != null && !PlayerStateList.PLAYING.equals(playerState)) {
                playerState = PlayerStateList.PLAYING;
            }
        }

        @Override
        public void onPaused() {
            handleOnPauseEvent();
        }

        @Override
        public void onStopped() {
            handleStopEvent();
        }

        @Override
        public void onBuffering(boolean isBuffering) {
            //intentionally left blank
        }

        @Override
        public void onSeekTo(int newPositionMillis) {
            handleOnPauseEvent();
        }
    });

    youTubePlayer.setPlayerStateChangeListener(new YouTubePlayer.PlayerStateChangeListener() {
        @Override
        public void onLoading() {
            //intentionally left blank
        }

        @Override
        public void onLoaded(String s) {
            //intentionally left blank
        }

        @Override
        public void onAdStarted() {
            //intentionally left blank
        }

        @Override
        public void onVideoStarted() {
            //intentionally left blank
        }

        @Override
        public void onVideoEnded() {
            handleStopEvent();
        }

        @Override
        public void onError(YouTubePlayer.ErrorReason errorReason) {
            //intentionally left blank
        }
    });

    player.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
        @Override
        public void onFullscreen(boolean b) {
            handleStopEvent();
        }
    });

    if (!restored) {
        youTubePlayer.loadVideo(getVideoId());
    }
}
 
Example 13
Source File: YoutubeOverlayFragment.java    From AndroidYoutubeOverlay with MIT License 4 votes vote down vote up
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult result) {
    LogHelper.logMessage("onInitializationFailure:" + result.name());
    this.player = null;
}
 
Example 14
Source File: CourseUnitYoutubePlayerFragment.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
                                    YouTubeInitializationResult result) {
    redirectToYoutubeDialog();
}
 
Example 15
Source File: ActionBarDemoActivity.java    From yt-android-player with Apache License 2.0 4 votes vote down vote up
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
  return (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
}
 
Example 16
Source File: PlayerActivity.java    From wmn-safety with MIT License 4 votes vote down vote up
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    if (youTubeInitializationResult.isUserRecoverableError()){
        youTubeInitializationResult.getErrorDialog(this,RECOVERY_REQUEST).show();
    }
}
 
Example 17
Source File: Fragment2.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer2, boolean restored) {

    mPlayer2 = youTubePlayer2;

    //Here we can set some flags on the player

    //This flag tells the player to switch to landscape when in fullscreen, it will also return to portrait
    //when leaving fullscreen
    mPlayer2.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);


    //This flag tells the player to automatically enter fullscreen when in landscape. Since we don't have
    //landscape layout for this activity, this is a good way to allow the user rotate the video player.
    mPlayer2.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);


    //This flag controls the system UI such as the status and navigation bar, hiding and showing them
    //alongside the player UI
    mPlayer2.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);


    if (mVideoId2 != null) {
        if (restored) {
            mPlayer2.play();
        } else {
            mPlayer2.loadVideo(mVideoId2);
        }
    }

}
 
Example 18
Source File: Fragment1.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer1, boolean restored) {

    mPlayer1 = youTubePlayer1;

    //Here we can set some flags on the player

    //This flag tells the player to switch to landscape when in fullscreen, it will also return to portrait
    //when leaving fullscreen
    mPlayer1.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);


    //This flag tells the player to automatically enter fullscreen when in landscape. Since we don't have
    //landscape layout for this activity, this is a good way to allow the user rotate the video player.
    mPlayer1.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);


    //This flag controls the system UI such as the status and navigation bar, hiding and showing them
    //alongside the player UI
    mPlayer1.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);


    if (mVideoId1 != null) {
        if (restored) {
            mPlayer1.play();
        } else {
            mPlayer1.loadVideo(mVideoId1);
        }
    }

}
 
Example 19
Source File: Fragment3.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer3, boolean restored) {

    mPlayer3 = youTubePlayer3;

    //Here we can set some flags on the player

    //This flag tells the player to switch to landscape when in fullscreen, it will also return to portrait
    //when leaving fullscreen
    mPlayer3.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);


    //This flag tells the player to automatically enter fullscreen when in landscape. Since we don't have
    //landscape layout for this activity, this is a good way to allow the user rotate the video player.
    mPlayer3.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);


    //This flag controls the system UI such as the status and navigation bar, hiding and showing them
    //alongside the player UI
    mPlayer3.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);


    if (mVideoId3 != null) {
        if (restored) {
            mPlayer3.play();
        } else {
            mPlayer3.loadVideo(mVideoId3);
        }
    }

}
 
Example 20
Source File: YouTubeFailureRecoveryActivity.java    From yt-android-player with Apache License 2.0 votes vote down vote up
protected abstract YouTubePlayer.Provider getYouTubePlayerProvider();