YTPlayerView load a list of videos

混江龙づ霸主 提交于 2019-12-24 02:04:02

问题


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


来源:https://stackoverflow.com/questions/38843732/ytplayerview-load-a-list-of-videos

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