Skip to content

Instantly share code, notes, and snippets.

@bobbyali
Created March 17, 2015 17:08
Show Gist options
  • Save bobbyali/be747b856d0a59bee054 to your computer and use it in GitHub Desktop.
Save bobbyali/be747b856d0a59bee054 to your computer and use it in GitHub Desktop.
An iOS youtube view controller.
import UIKit
import YouTubePlayer
class PlayerViewController: UIViewController, YouTubePlayerDelegate {
@IBOutlet var videoPlayer: YouTubePlayerView!
var videoID: String?
override func viewDidLoad() {
super.viewDidLoad()
videoPlayer.delegate = self
if let videoID = self.videoID {
videoPlayer.loadVideoID(videoID)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: YouTubePlayerDelegate
// These are all required. See https://github.com/gilesvangruisen/Swift-YouTube-Player/
func playerReady(videoPlayer: YouTubePlayerView) {
videoPlayer.play()
}
func playerStateChanged(videoPlayer: YouTubePlayerView, playerState: YouTubePlayerState) {
if videoPlayer.playerState == YouTubePlayerState.Ended || videoPlayer.playerState == YouTubePlayerState.Paused {
self.navigationController?.popViewControllerAnimated(true)
}
}
func playerQualityChanged(videoPlayer: YouTubePlayerView, playbackQuality: YouTubePlaybackQuality) {
println("Quality has changed")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment