I am building an iOS app that uses the youtube-ios-player-helper library to play YouTube videos. 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?
I had the same problem. But I solved it like this and it works well. in swift 4
private
->public
directly Execute