0
RecylerViewでAndroidのアクティビティにyoutubeプレイリストの10個の動画をリストするとき。私は間違いがないが、最後のビデオしか再生できない! 他の動画は読み込まれません。私はYouTubePlayerViewを使用RecyclerViewでYouTube動画を表示
、次のコードスニペットのように、
public class PlaylistViewAdapter extends RecyclerView.Adapter {
PlaylistItem[] playlist;
String APIKey;
public PlaylistViewAdapter(PlaylistItem[] c, String APIKey) {
playlist = c;
this.APIKey = APIKey;
}
class PlaylistItemData extends RecyclerView.ViewHolder {
TextView title;
TextView desc;
YouTubePlayerView videoPlayer;
public PlaylistItemData(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.title);
desc = (TextView) itemView.findViewById(R.id.desc);
videoPlayer = (YouTubePlayerView) itemView.findViewById(R.id.youtube_player_view);
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.playlist_row, parent, false);
PlaylistItemData dataObjectHolder = new PlaylistItemData(view);
return dataObjectHolder;
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
((PlaylistItemData) holder).videoPlayer.initialize(APIKey, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
// if (!b) {
youTubePlayer.cueVideo(playlist[position].getVideoId());
// }
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.i("onBindView", youTubeInitializationResult.toString());
}
});
((PlaylistItemData) holder).title.setText(playlist[position].getTitle());
((PlaylistItemData) holder).desc.setText(playlist[position].getDesc());
}
@Override
public int getItemCount() {
return playlist.length;
}
}
私はこの答えhttps://stackoverflow.com/a/36474697/1247399を見つけたので、私は、サムネイルやウェブビューを使用する必要がありますか?