YoutubeKit icon indicating copy to clipboard operation
YoutubeKit copied to clipboard

An error occuerd. Please try again later

Open tomoyasuzuki opened this issue 4 years ago • 3 comments

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.

tomoyasuzuki avatar Nov 04 '19 23:11 tomoyasuzuki

y_error

tomoyasuzuki avatar Nov 04 '19 23:11 tomoyasuzuki

this image is the almost same with the problem Im facing

tomoyasuzuki avatar Nov 04 '19 23:11 tomoyasuzuki

It happened with me at first time to play video after that it works fine, Does anyonne find the issue ?

islamshazly avatar May 17 '20 20:05 islamshazly

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.

rinov avatar May 21 '23 11:05 rinov