我已经关注了Net上的每一篇文章,但没有解决这个问题。 声音开始和停止权立即像0.1秒后。我可以很快听到声音。Swift:音频开始和停止.1秒
这里是真正重要的事情我的代码: ...
let path = NSBundle.mainBundle().pathForResource("bgMusic", ofType: "mp3")
let bgMusicURL = NSURL.fileURLWithPath(path!)
var backgroundMusicPlayer:AVAudioPlayer!
do{
try AVAudioSession.sharedInstance().setActive(true)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try backgroundMusicPlayer = AVAudioPlayer(contentsOfURL: bgMusicURL)
backgroundMusicPlayer!.prepareToPlay()
backgroundMusicPlayer!.play()
}catch {
print ("ERROR")
}
...
你还有其他的线程在运行吗? – brkr