Skip to content

Instantly share code, notes, and snippets.

@BramYeh
Last active August 10, 2018 06:06
Show Gist options
  • Save BramYeh/74e24d1f3da5379b2dd8107b13c02bbe to your computer and use it in GitHub Desktop.
Save BramYeh/74e24d1f3da5379b2dd8107b13c02bbe to your computer and use it in GitHub Desktop.
Utils for YouTubePlayerView
package com.google.android.youtube.player;
public class YouTubePlayerViewUtils {
public static YouTubePlayerView createYouTubePlayerView(final Activity activity,
final YouTubePlayer.OnInitializedListener initializedListener,
final Bundle playerState) {
// create YoutubePlayerView by private-package constructor
final YouTubePlayerView view = new YouTubePlayerView(context, /*AttributeSet*/ null, /*defStyleAttr*/ 0,
new YouTubePlayerView.b() {
@Override
public void a(YouTubePlayerView view,
String apiKey,
YouTubePlayer.OnInitializedListener listener) {
view.a(activity, view, apiKey, listener, playerState);
}
@Override
public void a(YouTubePlayerView view) {
// Do Nothing
}
});
// initialize YoutubePlayerView with API Key and OnInitializedListener
view.initialize(DeveloperKey.DEVELOPER_KEY, initializedListener);
return view;
}
public static Bundle getPlayerState(YouTubePlayerView view) {
return view.e();
}
/**
* The following methods sync from YouTubePlayerFragment and YouTubePlayerActivity
* We need to call these method by Fragment's lifecycle
*/
public static void start(YouTubePlayerView view) {
view.a();
}
public static void resume(YouTubePlayerView view) {
view.b();
}
public static void pause(YouTubePlayerView view) {
view.c();
}
public static void stop(YouTubePlayerView view) {
view.d();
}
public static void destroyView(YouTubePlayerView view, boolean isFinishing) {
view.c(isFinishing);
}
public static void destroy(YouTubePlayerView view, boolean isFinishing) {
view.b(isFinishing);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment