YTPlayerView加载视频列表

时间:2016-08-09 06:37:31

标签: ios swift youtube-api youtube-iframe-api ytplayerview

我正在尝试在我的应用上播放Youtube视频。我正在使用YTPlayerView库按视频ID播放视频。问题是当我尝试播放视频播放器列表时显示错误“发生错误。请稍后重试。(播放ID:someid)”。

我使用以下代码播放单个视频

@IBOutlet weak var playerView: YTPlayerView! // story board connection

let params = ["controls" : 2, "playsinline" : 1, "autohide" :1, "showinfo" : 0, "modestbranding" : 0, "cc_load_policy" : 0, "rel" : 1] //,
playerView.delegate = self
playerView.loadWithVideoId("v_I0rA72IJE", playerVars:params)

它适用于单个视频。但是,当我尝试使用以下代码加载视频列表时,我收到了该错误。

playerView.loadWithPlayerParams(params)
playerView.loadPlaylistByVideos(["v_I0rA72IJE","l-ujrOIL-9M","yw002vpbClA"], index: 0, startSeconds: 0, suggestedQuality: YTPlaybackQuality.Default)

playerView.cuePlaylistByVideos(["v_I0rA72IJE","l-ujrOIL-9M","yw002vpbClA"], index: 0, startSeconds: 0, suggestedQuality: YTPlaybackQuality.Default)

YTPlayerView error screen shot

请帮我解决这个问题。如果我做错了,请纠正我。

1 个答案:

答案 0 :(得分:1)

不是一个确切的解决方案,但我们现在可以继续

首先加载一个视频

youtubePlayerView.loadWithVideoId(videoId, playerVars: params)

playerViewDidBecomeReady(playerView: YTPlayerView)委托方法中加载该播放列表

func playerViewDidBecomeReady(playerView: YTPlayerView)
{
  playerView.cuePlaylistByVideos(videoIdsArray, index: 0, startSeconds: 0, suggestedQuality: YTPlaybackQuality.Default)
}