Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
override func viewDidLoad() {
super.viewDidLoad()
configureGestureRecognizer()
RestKitManager.getChannelToken(channel.name) { token in
if let token = token {
let params = "player=twitchweb&token=\(token.token)&sig=\(token.sig)&allow_source=true&type=any&p=3633125"
let set = NSCharacterSet.URLQueryAllowedCharacterSet()
let url2 = "http://usher.twitch.tv/api/channel/hls/\(self.channel.name).m3u8?" + params.stringByAddingPercentEncodingWithAllowedCharacters(set)!
let nsurl = NSURL(string: url2)
self.player = AVPlayer(URL: nsurl!)
let avPlayerLayer = AVPlayerLayer(player: self.player!)
avPlayerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
self.view.layer.addSublayer(avPlayerLayer)
self.player?.play()
}
}
}
// Using function as a completion block
override func viewDidLoad() {
super.viewDidLoad()
configureGestureRecognizer()
RestKitManager.getChannelToken(channel.name, completion: playUsingToken)
}
private func playUsingToken(token: Token?) {
if let token = token {
let params = "player=twitchweb&token=\(token.token)&sig=\(token.sig)&allow_source=true&type=any&p=3633125"
let set = NSCharacterSet.URLQueryAllowedCharacterSet()
let url2 = "http://usher.twitch.tv/api/channel/hls/\(self.channel.name).m3u8?" + params.stringByAddingPercentEncodingWithAllowedCharacters(set)!
let nsurl = NSURL(string: url2)
self.player = AVPlayer(URL: nsurl!)
let avPlayerLayer = AVPlayerLayer(player: self.player!)
avPlayerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
self.view.layer.addSublayer(avPlayerLayer)
self.player?.play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment