我有一个listView,其中
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int pos, long id) {
player.cueVideo("KJ9KzGQq0w");
}
});
private YouTubePlayer player= new YouTubePlayer() {
@Override
public void setShowFullscreenButton(boolean arg0) {
// TODO Auto-generated method stub
}
@Override
public void setPlaylistEventListener(PlaylistEventListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void setPlayerStyle(PlayerStyle arg0) {
// TODO Auto-generated method stub
}
@Override
public void setPlayerStateChangeListener(PlayerStateChangeListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void setPlaybackEventListener(PlaybackEventListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void setOnFullscreenListener(OnFullscreenListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void setManageAudioFocus(boolean arg0) {
// TODO Auto-generated method stub
}
@Override
public void setFullscreenControlFlags(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void setFullscreen(boolean arg0) {
// TODO Auto-generated method stub
}
@Override
public void seekToMillis(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void seekRelativeMillis(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void release() {
// TODO Auto-generated method stub
}
@Override
public void previous() {
// TODO Auto-generated method stub
}
@Override
public void play() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void next() {
// TODO Auto-generated method stub
}
@Override
public void loadVideos(List<String> arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void loadVideos(List<String> arg0) {
// TODO Auto-generated method stub
}
@Override
public void loadVideo(String arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void loadVideo(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void loadPlaylist(String arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void loadPlaylist(String arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean isPlaying() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasPrevious() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getFullscreenControlFlags() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getDurationMillis() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getCurrentTimeMillis() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void cueVideos(List<String> arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void cueVideos(List<String> arg0) {
// TODO Auto-generated method stub
}
@Override
public void cueVideo(String arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void cueVideo(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void cuePlaylist(String arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void cuePlaylist(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void addFullscreenControlFlag(int arg0) {
// TODO Auto-generated method stub
}
};
我正在使用YouTubeAPI
来执行此操作
API中的示例代码
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,boolean wasRestored) {
if (!wasRestored) {
//player.cueVideo("wKJ9KzGQq0w");
}
}
我想在点击listView中的元素后立即播放视频。
答案 0 :(得分:0)
将您的player.cueVideo("wKJ9KzGQq0w");
更改为player.loadVideo("wKJ9KzGQq0w");
。
loadVideo将在加载完成后自动播放。
答案 1 :(得分:0)
做了一些改变
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player1,boolean wasRestored) {
player=player1;
}
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int pos, long id) {
video_URL="eF9AC2Ce2ow";
video_player.loadVideo(video_URL);
}});