如何以编程方式获取Youtube视频网址

时间:2015-11-26 11:13:53

标签: android youtube playlist android-youtube-api

Youtube播放列表中,我有很多Videos,现在我想与其他人分享Videos(使用视频网址 - 现在正在播放)

我使用以下代码在YouTube应用中播放Android播放列表:

public static final String PlayList_ID = "PLP7qPet500dfglA7FFTxBmB_snxCaMHDJ";

 @Override
 public void onInitializationSuccess(Provider provider, YouTubePlayer player,
   boolean wasRestored) {

  youTubePlayer = player;

  Toast.makeText(getApplicationContext(), 
    "YouTubePlayer.onInitializationSuccess()", 
    Toast.LENGTH_LONG).show();

  youTubePlayer.setPlayerStateChangeListener(myPlayerStateChangeListener);
  youTubePlayer.setPlaybackEventListener(myPlaybackEventListener);

  if (!wasRestored) {
   player.cuePlaylist(PlayList_ID);
  }

 }

1 个答案:

答案 0 :(得分:1)

在onLoaded()中你可以从你可以创建url的id获取id。

你可以这样。

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
        boolean wasRestored) {

    player.setPlayerStateChangeListener(new PlayerStateChangeListener() {

        @Override
        public void onVideoStarted() {
        }

        @Override
        public void onVideoEnded() {
        }

        @Override
        public void onLoading() {
        }

        @Override
        public void onLoaded(String mVideoId) {
            String url = "http://www.youtube.com/watch?v=" + mVideoId
        }

        @Override
        public void onError(ErrorReason reason) {
        }

        @Override
        public void onAdStarted() {
        }
    });
}