我想完全从网址加载声音,然后播放它:
我使用Heneke库来获取缓存结果。
if let soundUrl = URL(string: "http://wow.zamimg.com/hearthhead/sounds/ruru/VO_NEW1_010_Play_01.mp3") {
Shared.dataCache.fetch(URL: soundUrl).onSuccess { soundData in
DispatchQueue.main.async {
do {
var audioPlayer = try AVAudioPlayer(data: soundData)
audioPlayer.prepareToPlay()
audioPlayer.volume = 1.0
audioPlayer.play()
} catch let error as NSError {
print(error.localizedDescription)
}
}
}
}
audioPlayer.prepareToPlay()
- 返回true
soundData
- 不是nil