我从iTunes搜索API获取链接,并尝试将其传递到AVPlayer,但出现错误。 http://puu.sh/ldBCw/6bfff69c7d.png。以下是获取链接的代码。如何播放AVPlayer中的链接?
let task = NSURLSession.sharedSession().dataTaskWithURL(url) {(data, response, error) -> Void in
do {
if let dict: NSDictionary = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary
{
if let previewUrl = dict["results"]![0]["previewUrl"] {
print(previewUrl!)
player = AVPlayer(URL: previewUrl)
}
}
} catch let jsonError as NSError {
}
}
task.resume()
}