2017-05-03 65 views
0

我試圖打一些使用Android Studio中的YouTube播放器API從YouTube視頻。我有每個視頻的視頻ID。現在我希望播放器在每個按鈕被點擊時播放視頻。如何在Youtubeplayer中播放多個視頻 - API?

 @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
  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 
       } 
+0

thnkx siddarth的幫助 –

+0

我想在活動Youtubeplayerview –

+0

播放視頻一次嘗試這個工作對我來說 – siddharth

相關問題