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

How to Get Youtube Video URL Programmatically

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

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

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);
  }

 }

在 onLoaded() 中,您可以从您可以创建的 ID 中获取 ID url。

你可以这样。

@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() {
        }
    });
}