我正在使用android youtube Api.i成功创建youtube Api project.i可以用youtube播放视频Api.now我想跳过按钮click.i写的一些代码可以跳过视频 ,但是当我点击按钮我有床结果.YouTubePlayerView加载两次。 这是我的代码
public class MainActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
static private final String DEVELOPER_KEY = "***********";
private String VIDEO = "*******";
private Button b1;
private YouTubePlayer player1;
public int endTime = 65000;
private PlayerStyle style;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
b1 = (Button) findViewById(R.id.button1);
youTubeView.initialize(DEVELOPER_KEY, this);
youTubeView.setEnabled(false);
style = PlayerStyle.CHROMELESS;
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int[] array = new int[] { 36000, 40000, 50000, 60000, 70000,
80000 };
Random random = new Random();
final int index = array[random.nextInt(array.length)];
Log.e("randommmmmmmmmmmm", String.valueOf(index));
player1.loadVideo(VIDEO, index);
}
});
}
@Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! " + error.toString(), Toast.LENGTH_LONG)
.show();
}
@Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
this.player1 = player;
player1.setPlayerStyle(style);
player.loadVideo(VIDEO);
}
}
我在做错了什么?如果有人知道解决方案,请帮助我答案 0 :(得分:0)
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() {
}
};
您可以将此侦听器添加到youtubePlayer实例。 要么 如果您试图通过单击按钮来寻找特定时间,那么您可以执行以下操作:
YouTubePlayer.seekToMillis (int milliSeconds);