Created
December 15, 2016 16:52
-
-
Save kkdroidgit/d3505c317c14779614f675487ff4ed97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.paperwrrk; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.multidex.MultiDex; | |
import android.view.View; | |
import android.widget.Button; | |
import com.google.android.youtube.player.YouTubeBaseActivity; | |
import com.google.android.youtube.player.YouTubeInitializationResult; | |
import com.google.android.youtube.player.YouTubePlayer; | |
import com.google.android.youtube.player.YouTubePlayerView; | |
public class MainActivity extends YouTubeBaseActivity implements View.OnClickListener { | |
Button mbutton; | |
Button btn2; | |
private YouTubePlayerView myouTubePlayerView; | |
private YouTubePlayer.OnInitializedListener monInitializedListener; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
myouTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player_view); | |
monInitializedListener = new YouTubePlayer.OnInitializedListener() { | |
@Override | |
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) { | |
youTubePlayer.loadVideo("_GuOjXYl5ew"); | |
} | |
@Override | |
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) { | |
} | |
}; | |
mbutton = (Button) findViewById(R.id.button_play_youtube_video); | |
btn2 =(Button) findViewById(R.id.btn2); | |
mbutton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
myouTubePlayerView.initialize("Your API-KEY", monInitializedListener);// you can also have a separate class for API KEY | |
} | |
}); | |
} | |
@Override | |
public void onClick(View view){ | |
if (view == btn2){ | |
startActivity(new Intent(this, Activity2.class)); | |
} | |
} | |
@Override | |
protected void attachBaseContext(Context newBase) { | |
super.attachBaseContext(newBase); | |
MultiDex.install(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment