var audioPlayer:AVAudioPlayer!
func playsong(musicdata:NSData){
do{
try audioPlayer = AVAudioPlayer(data: musicdata)
audioPlayer.prepareToPlay()
audioPlayer.play()
}catch {
print(error)
}
}
let str = "http://xxx/xxx.mp3"
let url = NSURL(string: str)
let configDefault = NSURLSessionConfiguration.defaultSessionConfiguration()
configDefault.timeoutIntervalForRequest = 15
let session1 = NSURLSession(configuration: configDefault)
let dataTask = session1.dataTaskWithURL(url!, completionHandler: {(data,response,error)->Void in
print(error)
playsong(data!)
})
dataTask.resume()