我在我的应用程序中使用 Youtube API ,并希望在其中使用Youtube standAlone播放器,但我没有得到如何在我的应用程序中实现它,因为我使用 Firebase作为数据库。我已经经历了很多论坛和Youtube独立播放器文档,但它没有提供任何有用的帮助,请帮忙。
我正在使用Android Studio
Firebase适配器类文件:
FirebaseRecyclerAdapter <post, postViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<post, postViewHolder>(
post.class,
R.layout.post_row_recycle_home,
postViewHolder.class,
mDatabaseReference
){
@Override
protected void populateViewHolder(postViewHolder viewHolder, post model, int position) {
viewHolder.setYoutube(model.getYoutube());
};
mrecyclerView.setAdapter(firebaseRecyclerAdapter);
public static class postViewHolder extends RecyclerViewPager.ViewHolder{
View mView;
public postViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setYoutube(final String youtube){
final YouTubePlayerView youPlay = (YouTubePlayerView) mView.findViewById(R.id.youtuber);
youPlay.initialize("SOME KEY",
new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo(youtube);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult youTubeInitializationResult) {
}
});
}