我正在寻找一种在 AVAudioPlayer 中使用 RMTP 网址实现音频流的好方法。 有什么方法可以做到这一点?还是有什么建议吗?
由于
更新1:包含代码
所以这是代码:
let queue : dispatch_queue_t = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
dispatch_async(queue, { () -> Void in
if let songData = NSData(contentsOfURL: url) {
if let player = AVAudioPlayer(data: songData, error: nil) {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.audioPlayer = player
self.audioPlayer!.delegate = self
if let startTime = startingTime {
self.audioPlayer?.currentTime = startTime
}
self.audioPlayer!.prepareToPlay()
self.audioPlayer!.play()
self.delegate?.mmPlayerManagerDelegate_playerStartedPlaying()
})
}
}
else {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if appDelegate.bIsCurUserListener == false {
//=> Call delegate
self.delegate?.mmPlayerManagerDelegate_prepareNextSongToPlay()
}
})
}
})
网址在这里: