YTPlayerView load a list of videos

2019-07-08 10:41发布

问题:

i am trying to play Youtube videos on my app. I am using YTPlayerView library for playing a video by video id. Problem is when i am trying to play a list of videos player showing an error that "An error occurred. Please try again later. (Playback ID: someid)".

I am using the following code for playing a single video

@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)

Its working fine for a single video. But when i try to load a list of videos by using the following code i am getting that error.

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

or

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

Please help me to solve the issue. Please correct me if i am doing anything wrong.

回答1:

Not an exact solution, but we can proceed for now

First load a single video

youtubePlayerView.loadWithVideoId(videoId, playerVars: params)

inside the playerViewDidBecomeReady(playerView: YTPlayerView) delegate method load that playlist

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