How can I play YouTube live streams with the YouTube Android Player API?

微笑、不失礼 提交于 2019-12-20 04:56:06

问题


I have managed to play YouTube videos using YouTubePlayer. However, when I try to play live streams using YouTubePlayer, nothing happens. Is playing live streams supported by the API? If so, how do I do it?


回答1:


There is no difference in playing normal YouTube videos and live videos.I was unable to play live videos on android version 4.1. however on version 4.2.2, live videos played successfully. Latest version of Official Youtube app must be installed in order to use API. Code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);   

  YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
  youTubeView.initialize(DEVELOPER_KEY, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
        YouTubePlayer player, boolean wasRestored) {

    player.loadVideo("UT86BH2LVUU"); //live vid

}


来源:https://stackoverflow.com/questions/21121259/how-can-i-play-youtube-live-streams-with-the-youtube-android-player-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!