Created
March 17, 2015 17:08
-
-
Save bobbyali/be747b856d0a59bee054 to your computer and use it in GitHub Desktop.
An iOS youtube view controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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