我正在使用框架在Swift中播放Youtube视频:https://github.com/gilesvangruisen/Swift-YouTube-Player。 该框架提供了委托方法,但我似乎无法解决它们。其他人已经开始工作了,所以我确定问题就在我身边。
import UIKit
import YouTubePlayer
class MainPlayerController: UIViewController, YouTubePlayerDelegate {
@IBOutlet var playerView: YouTubePlayerView!
override func viewDidLoad() {
super.viewDidLoad()
let myVideoURL = NSURL(string: "https://www.youtube.com/watch?v=OGe-WXhbmBg")
playerView.delegate = self
playerView.loadVideoURL(myVideoURL! as URL)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func play(_ sender: AnyObject) {
playerView.play()
}
//The 3 functions below will not fire
func playerStateChanged(videoPlayer: YouTubePlayerView, playerState: YouTubePlayerState) {
print("playerStateChanged")
}
func playerReady(videoPlayer: YouTubePlayerView) {
print("playerReady")
}
func playerQualityChanged(videoPlayer: YouTubePlayerView, playbackQuality: YouTubePlaybackQuality) {
print("playerQualityChanged")
}
}
播放器工作正常并将播放。我试图让playerReady()函数特别有效。任何帮助都会很棒,谢谢。
答案 0 :(得分:0)
“尝试在每个方法的第一个参数之前添加下划线。即。playerReady(_ videoPlayer:...)” -Viktor Gardart