我试图制作一个使用youtube API播放实时新闻频道的Android应用程序,但是当我尝试播放频道时,它始终会显示白色的空白屏幕。
code:MainActivity
watch=(Button)findViewById(R.id.samacharBtn);
watch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(getApplicationContext(),PlayerActivity.class);
startActivity(intent);
}
});
code:PlayerActivity
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.yt_player);
YouTubePlayerView playerView = (YouTubePlayerView) findViewById(R.id.youTubePlayerView);
playerView.initialize(DeveloperKey.DEVELOPER_KEY, this);
fullScreen = (Button) findViewById(R.id.buttonFullScr);
fullScreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player.setFullscreen(true);
}
});
}
@Override
public void onI[![enter image description here][1]][1]nitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean b) {
this.player = player;
Log.e(TAG,"Video"+ provider);
if (!b) {
player.loadVideo("XXXXXXX");
player.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL);
}
}