class testYoutubeViewController: UIViewController, YTPlayerViewDelegate {
@IBOutlet weak var playerView: YTPlayerView!
override func viewDidLoad() {
super.viewDidLoad()
self.playerView.delegate = self
let playerVars = ["playsinline": 0, "showinfo":0, "controls": 0, "autohide":1]
playerView.load(withVideoId: "OsINvu5FYKg", playerVars: playerVars)
//playerView.load(withVideoId: "M7lc1UVf-VE")
//playerView.playVideo()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
playerView.playVideo()
}
func playerView(_ playerView: YTPlayerView, didChangeTo state: YTPlayerState) {
switch state {
case .playing:
print("Stared Playback")
case .paused:
print("Paused")
case .ended:
print("Ended")
case .buffering:
print("buffering")
case .unstarted:
print("unstartd")
case .queued:
print("playing queued")
default:
break
}
}
func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
playerView.playVideo()
}
}
*我想添加一个观察者来检测我何时完成或放大youtube视频播放器。 *视频效果很好,能够控制播放,暂停,下一个视频,等等https://developers.google.com/youtube/js_api_reference#cuePlaylistObj。但是我没有看到用于检测完成和缩放按钮的事件示例。