我在我的安卓代码中使用了Youtube api,当我以纵向模式播放视频时,它会在一秒后暂停,但是当我在全屏(风景)模式下播放它时,它可以正常工作。以下是一些相关代码:
YouTubePlayerView youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player);
youTubePlayerView.initialize(API_KEY, this);
@覆盖
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
player.setPlayerStateChangeListener(playerStateChangeListener);
player.setPlaybackEventListener(playbackEventListener);
//** Start buffering **//*
if (!wasRestored) {
player.cueVideo("video ID");
}
player.getDurationMillis();
}
private PlaybackEventListener playbackEventListener = new PlaybackEventListener() {
@Override
public void onBuffering(boolean arg0) {
}
@Override
public void onPaused() {
}
@Override
public void onPlaying() {
}
@Override
public void onSeekTo(int arg0) {
}
@Override
public void onStopped() {
btn.setVisibility(View.VISIBLE);
}
};
private PlayerStateChangeListener playerStateChangeListener = new PlayerStateChangeListener() {
@Override
public void onAdStarted() {
}
@Override
public void onError(ErrorReason arg0) {
}
@Override
public void onLoaded(String arg0) {
}
@Override
public void onLoading() {
}
@Override
public void onVideoEnded() {
}
@Override
public void onVideoStarted() {
}
};
}