0

How to get youtube key_vedio_id please help me to find-out this problem. This is my code please and correct me if i wrong any where.

public class YouTubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

    private static final int RECOVERY_DIALOG_REQUEST = 1;

    public static final String KEY_VIDEO_ID = "KEY_VIDEO_ID";

    private String mVideoId;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_youtube);

        final Bundle arguments = getIntent().getExtras();
        if (arguments != null && arguments.containsKey(KEY_VIDEO_ID)) {
            mVideoId = arguments.getString(KEY_VIDEO_ID);
        }

        final YouTubePlayerView playerView = (YouTubePlayerView) findViewById(R.id.youTubePlayerView);
        playerView.initialize(getString(R.string.DEVELOPER_KEY_YOU_TUBE), this);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean restored) {

        //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
        youTubePlayer.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.
        youTubePlayer.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
        youTubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);

        if (mVideoId != null) {
            if (restored) {
                youTubePlayer.play();
            } else {
                youTubePlayer.loadVideo(mVideoId);
            }
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
        if (youTubeInitializationResult.isUserRecoverableError()) {
            youTubeInitializationResult.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
        } else {
            //Handle the failure
            Toast.makeText(this, R.string.error_init_failure, Toast.LENGTH_LONG).show();
        }
    }
}
jayeshsolanki93
  • 2,096
  • 1
  • 20
  • 37
Umesh
  • 86
  • 8
  • What exactly is wrong with this code? `arguments.containsKey(KEY_VIDEO_ID)` isn't getting anything? How are you starting the Activity? – OneCricketeer Jul 19 '16 at 12:29
  • where i can get the key_video_id and play you-tube video. – Umesh Jul 19 '16 at 12:32
  • You get it from the Intent that was sent to the activity you show. So again, how are you starting this activity? – OneCricketeer Jul 19 '16 at 12:35
  • //Check for any issues final YouTubeInitializationResult result = YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(this); if (result != YouTubeInitializationResult.SUCCESS) { //If there are any issues we can show an error dialog. result.getErrorDialog(this,0).show(); } } – Umesh Jul 19 '16 at 12:35
  • Please [edit] your question to include more code. Do not comment with it – OneCricketeer Jul 19 '16 at 12:36
  • This is how I am starting activity startActivity(YouTubeIntents.createPlayVideoIntent(context, video.id)); – Umesh Jul 19 '16 at 12:38
  • Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – OneCricketeer Jul 19 '16 at 12:39
  • You have the getExtra code. You need the putExtra code – OneCricketeer Jul 19 '16 at 12:41

0 Answers0