Hey this is what i'm implementing in my app for you tube video play
public class Youtubevideo extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener
{
public static final String API_KEY = "Use Your API key For youtube api";
//http://youtu.be/<VIDEO_ID>
//sample video id
public String VIDEO_ID = "abcdefgh";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** attaching layout xml **/
setContentView(R.layout.youtubevideo);
Intent dataReceived = getIntent();
if(dataReceived != null)
{
VIDEO_ID = dataReceived.getStringExtra("url");
}
/** Initializing YouTube player view **/
YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
youTubePlayerView.initialize(API_KEY, this);
}
@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
Toast.makeText(this, "Failured to Initialize!", Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
/** add listeners to YouTubePlayer instance **/
//player.setPlayerStateChangeListener(playerStateChangeListener);
//player.setPlaybackEventListener(playbackEventListener);
player.setFullscreen(true);
player.setShowFullscreenButton(true);
/** Start buffering **/
if (!wasRestored) {
player.cueVideo(VIDEO_ID);
}
}
private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {
@Override
public void onBuffering(boolean arg0) {
}
@Override
public void onPaused() {
}
@Override
public void onPlaying() {
}
@Override
public void onSeekTo(int arg0) {
}
@Override
public void onStopped() {
}
};
private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {
@Override
public void onAdStarted() {
}
@Override
public void onError(ErrorReason arg0) {
}
@Override
public void onLoaded(String arg0) {
}
@Override
public void onLoading() {
}
@Override
public void onVideoEnded() {
}
@Override
public void onVideoStarted() {
}
};
}
and xml will be like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="5dp" />
</LinearLayout>
and in build.gradle use the Youtube jar lib openly available:
compile files('libs/YouTubeAndroidPlayerApi.jar')
hope this will help.
:)
YouTubePlayer.PlayerStyle.MINIMAL
– Friede