下面是我在活动中使用的代码,我在其中嵌入了YouTube播放器! 简而言之,实时流的videoId是通过youtube数据API调用传递给youtube播放器的。
每当我尝试在嵌入式层上播放实时流时,视频将在2秒后暂停! 我之前创建了一个演示应用程序,以检查嵌入YT Player的可行性。视频流在该应用程序中没有任何问题!我在这里实现了相同的代码,但是我面临上述问题!
@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;}
}
答案 0 :(得分:0)
检查您的logcat。您的视图不能与YouTubePlayer重叠。