1:youtube player可以通过id 或url来播放视频
主要用到的两个方法是 loadWithVideoId 和 loadVideoByURL
这两者的区别是 loadVideoByURL加载完之后会自动播放的
loadWithVideoId不会自动播放 加载完之后会显示第一政的图和一个播放按钮
private extension NSURL {
func queryStringComponents() -> [String: AnyObject] {
var dict = [String: AnyObject]()
// Check for query string
if let query = self.query {
// Loop through pairings (separated by &)
for pair in query.componentsSeparatedByString("&") {
// Pull key,val from from pair parts (separated by =) and set dict[key] = value
let components = pair.componentsSeparatedByString("=")
if (components.count > 1) {
dict[components[0]] = components[1]
}
}
}
return dict
}
}
public func videoIDFromYouTubeURL(videoURL: NSURL) -> String? { if let host = videoURL.host,pathComponents = videoURL.pathComponents where pathComponents.count > 1 && host.hasSuffix("youtu.be") { return pathComponents[1] } return videoURL.queryStringComponents()["v"] as? String }