Browser plugin / Flash based Embed
Browser plugin / Flash based Embed
Browser plugin / Flash based Embed
iFrame Based Embed
Browser plugin / Flash based Embed
iFrame Based Embed
Browser plugin / Flash based Embed
iFrame Based Embed
Launch video in Native YouTube Application
Browser plugin / Flash based Embed
iFrame Based Embed
Launch video in Native YouTube Application
YouTube.initialize(context, YOUTUBE_DEVELOPER_KEY); Intent intent = YouTubePlayerActivity.createIntent(context, videoId); startActivity(intent);
This is a Player API, not a Data API
Tony Jacobs
www.gloto.com
Tony Jacobs
www.gloto.com
YouTubePlayerActivity
YouTubePlayerActivity
public void onCreate() { ... YouTube.initialize(this, YOUTUBE_DEVELOPER_KEY); } private void playVideo(String videoId) { Intent intent = YouTubePlayerActivity.createIntent(this, videoId); startActivity(intent); }
YouTubePlayerActivity
public void onCreate() { ... YouTube.initialize(this, YOUTUBE_DEVELOPER_KEY); } private void playVideo(String videoId) { Intent intent = YouTubePlayerActivity.createIntent(this, videoId); startActivity(intent); } private void playVideosInLightbox(ArrayList<String> videoIds, int startIdx) { Intent intent = YouTubePlayerActivity.createIntent(this, videoIds, startIdx, true); startActivity(intent); }
YouTubePlayerFragment / YouTubePlayerView
YouTubePlayerFragment
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"> <fragment android:name="com.google.android.youtube.api.YouTubePlayerFragment" android:id="@+id/youtube_fragment"/> </RelativeLayout>
public class PlayerFragmentDemoActivity { ... private void loadVideo(String videoId) { YouTubePlayer youTubePlayer = getFragmentManager().findFragmentById(R.id.youtube_fragment); youTubePlayer.loadVideo(videoId); } }
YouTubePlayerView
public class PlayerViewDemoActivity extends YouTubeBaseActivity { private YouTubePlayer player; public void onCreate(Bundle saveInstanceState) { super.onCreate(saveInstanceState); player = new YouTubePlayerView(); registerPlayerView(youTubePlayerView); setContentView(playerView); } private void loadVideo(String videoId) { playerView.loadVideo(videoId); } }
public class FullscreenDemoActivity implements OnFullscreenListener { private boolean fullscreen; public void onCreate(Bundle saveInstanceState) { player.enableCustomFullscreen(this); } private void doLayout() { if (fullscreen) { // YouTube library automatically deals with orientation changes and hiding system UI playerView.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT)); otherViews.setVisibility(View.GONE); } else { /* non-fullscreen layout */ } } public void onFullscreen(boolean isFullscreen) { fullscreen = isFullscreen; doLayout(); } public void onConfigurationChanged(Configuration configuration) { doLayout(); }}