我正在尝试使用Android Studio中的YouTube播放器API播放YouTube上的一些视频。我有每个视频的视频ID。现在我希望玩家在点击每个按钮时播放视频。
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo("video_id");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
当我使用这种方法时,我不知道如何在点击第二个按钮以在同一个播放器中播放第二个视频时“更改视频ID”。
非常感谢任何答案!
答案 0 :(得分:0)
YouTubePlayer player;//Inilize this in before oncreate method
videos_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedurl=videoslist.get(position); //videolist is the list of all video view ids
player.pause();
player.cueVideo(selectedurl);
}
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored)
{
this.player=player;
if (!wasRestored) {
player.cueVideo(videoslist.get(0)); // Plays https://www.youtube.com/watch?v=videoid
}