youtube / youtube-ios-player-helper

Lightweight helper library that allows iOS developers to add inline playback of YouTube videos through a WebView
Other
1.65k stars 683 forks source link

setPlaybackRate doesn't work #298

Open marcosatanaka opened 6 years ago

marcosatanaka commented 6 years ago

I'm trying to set the playback speed, but nothing happens:

class PlayerViewController: UIViewController {

    private let player = YTPlayerView()

    override func viewDidLoad() {
        super.viewDidLoad()

        player.delegate = self
        view.addSubview(player)
        setupPlayerConstraints()

        player.load(withVideoId: "123456")
        // Tried here, but nothing change: 
        print("Available playback rates: \(String(describing: player.availablePlaybackRates()))")
        player.setPlaybackRate(2.0)
    }

}

extension PlayerViewController: YTPlayerViewDelegate {

    func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
        player.playVideo()
    }

    func playerView(_ playerView: YTPlayerView, didChangeTo state: YTPlayerState) {
        switch (state) {
        case.playing:
            // Tried here, but again, nothing change:
            print("Available playback rates: \(String(describing: player.availablePlaybackRates()))")
            player.setPlaybackRate(2.0)
        default:
            break;
        }
    }

}

As shown by the code above, I've tried setting playback speed after loading the video and also when player changes it's state to playing. In none of then the speed was changed.

Also, player.availablePlaybackRates returns nil in both cases (that's strange because when I watch the same video using the YouTube app, I can change the playback speed).

I know that setting the playback speed is a suggestion to the player, but on the official YouTube app, changing the speed works for the same video that I'm trying to watch on my app.

Is there anything that I'm missing here?

Livadas commented 5 years ago

"2.0" isn't supported but "2" is. 🙄