AVAudioPlayer播放声音异步无法正常工作

时间:2016-10-15 13:18:01

标签: ios swift avaudioplayer

我想完全从网址加载声音,然后播放它:

我使用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

0 个答案:

没有答案