如何使用带Firebase的Youtube API播放视频?

时间:2017-07-05 05:08:58

标签: android firebase firebase-realtime-database youtube-api

要做到这一点:

1.-我将实例制作成firebase

  mDatabase = FirebaseDatabase.getInstance().getReference().child("Videos");

2.-然后我将布局链接到代码

mNoticiasSingleTitle = (TextView)findViewById(R.id.post_titleNoti);
mNoticiasSingleImage = (ImageView) findViewById(R.id.imageView);
mNoticiasSingleVid = (YouTubePlayerView) findViewById(R.id.videoView);

3.-我在onDataChange(DataSnapshot dataSnapshot){}

中工作

   String post_title = (String)dataSnapshot.child("title").getValue();
   String post_image = (String)dataSnapshot.child("image").getValue();
   String post_video = (String)dataSnapshot.child("vid").getValue();

   mNoticiasSingleTitle .setText(post_consejo);  
   Picasso.with(VideoAct.this).load(post_image).into(mNoticiasSingleImage);
   //Missing code here 

要加载图片我使用毕加索,如果我想上传youtube的视频,请帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

这样做。

youTubePlayerView.initialize("YOUR API KEY",
            new YouTubePlayer.OnInitializedListener() {
                @Override
                public void onInitializationSuccess(YouTubePlayer.Provider provider,
                        YouTubePlayer youTubePlayer, boolean b) {


                    youTubePlayer.loadVideo("VIDEO_ID_HERE");
                }
                @Override
                public void onInitializationFailure(YouTubePlayer.Provider provider,
                        YouTubeInitializationResult youTubeInitializationResult) {

                }
    });