YoutubeKit
YoutubeKit copied to clipboard
An error occuerd. Please try again later
Hi! I am trying to Make Youtube app with YoutubeKit. I think it's cheaper to explain the problem I'm facing with the code.
This is my CustomCell code.
final class VideoCell: UICollectionViewCell, YTSwiftyPlayerDelegate {
private var player: YTSwiftyPlayer!
private var id: String = ""
override init(frame: CGRect) {
super.init(frame: frame)
configurePlayer()
configureConstraints()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//MARK: Player
extension VideoCell {
func configurePlayer() {
player = YTSwiftyPlayer(
frame: CGRect(x: 0, y: 0, width: 375, height: 237),
playerVars: [
.playsInline(true),
.videoID(self.id),
.loopVideo(true),
.showRelatedVideo(false)
])
player.autoplay = false
// Set player view
addSubview(player)
// Set delegate for detect callback information from the player
player.delegate = self
// Load video player
player.loadPlayer()
}
func bind(video: Video) {
self.id = video.id
}
}
This Code is does not work properly.
Error message is
An error occuerd. Please try again later.
this image is the almost same with the problem Im facing
It happened with me at first time to play video after that it works fine, Does anyonne find the issue ?
This issue seems to be occurring because self.id is empty when the configurePlayer() method is called. The self.id is set in the bind(video: Video) method, but this happens after the configurePlayer() method is called.
Therefore, when you set .videoID(self.id) in the configurePlayer() method, it causes an error because self.id is empty at that point.
To resolve this issue, you could consider setting up the player after the bind(video: Video) method is called. Specifically, you could call the configurePlayer() method within the bind(video: Video) method.