Below is the code I have used inside the activity here I have embedded the youtube player! In a nutshell, the videoId of the Live Stream is being passed to the youtube player from a youtube Data API call.
Whenever I try to play the live stream on the embedded layer, the video pauses after 2 seconds! I created a demo app earlier to check the feasibility of embedding the YT Player. The video is streaming without any problems in that app! I have implemented the same code here but I am facing the above mentioned issue!
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_video);
youTubePlayerView = findViewById(R.id.youtubeView);
youTubePlayerView.initialize(API_KEY, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
Bundle bundle = getIntent().getExtras();
String showVideo = bundle.getString(ConstantsYtPlayer.VIDEO_ID);
youTubePlayer.cueVideo(showVideo);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
if(youTubeInitializationResult.isUserRecoverableError()){
youTubeInitializationResult.getErrorDialog(this, RECOVERY_REQUEST).show();
}else{
Toast.makeText(VideoActivity.this, "Error Initializing Youtube Player", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == RECOVERY_REQUEST){
getYoutubePlayerProvider().initialize(API_KEY, this);
}
}
protected YouTubePlayer.Provider getYoutubePlayerProvider(){
return youTubePlayerView;}
}
Check your logcat. You cannot have views overlapping the YouTubePlayer.