JOHN JOHNNNY

JOHN JOHNNNY

  • 1.7k
  • 190
  • 99.5k

start youtube player activity by passing selected video id v

Apr 7 2018 9:27 AM
Below is my list of youtube video ids in a switch statement house in onclicklistener method
when user clicks each cardview i want each video to be open in a YouTubePlayerView, i created
four separate YouTubePlayerView activity for each video which is not ideal. My question is how can
parse each youtube video id from activity that contains the switch statement to YouTubePlayerView activity
i.e each videos can be watched using one YouTubePlayerView activity


switch (pos) {
case 0: {
Intent mIntent = new Intent(mContext, QuickPlayActivity1.class);
mIntent.putExtra(Constants.YOUTUBE_VIDEO_KEY, "v=zOvZwQP_-u8");
mContext.startActivity(mIntent);
break;
}
case 1: {
Intent mIntent1 = new Intent(mContext, QuickPlayActivity2.class);
mIntent1.putExtra(Constants.YOUTUBE_VIDEO_KEY, "lHtrJJz7sHc");
mContext.startActivity(mIntent1);
break;
}
case 2: {
Intent mIntent2 = new Intent(mContext, QuickPlayActivity3.class);
mIntent2.putExtra(Constants.YOUTUBE_VIDEO_KEY, "m6kMdUpAFdo");
mContext.startActivity(mIntent2);
break;
}
case 3: {
Intent mIntent3 = new Intent(mContext, QuickPlayActivity4.class);
mIntent3.putExtra(Constants.YOUTUBE_VIDEO_KEY, "m2JYPXBxDYQ");
mContext.startActivity(mIntent3);
break;
}

}

YouTubePlayerView activity

public class QuickPlayActivity extends YouTubeBaseActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quick_play);

YouTubePlayerView youTubePlayerView =
(YouTubePlayerView) findViewById(R.id.player);

youTubePlayerView.initialize("YOUR API KEY",
new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer youTubePlayer, boolean b) {

// do any work here to cue video, play video, etc.
youTubePlayer.cueVideo("5xVh-7ywKpE");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult youTubeInitializationResult) {

}
});
}

Answers (2)