【发布时间】:2015-07-21 05:27:29
【问题描述】:
我正在尝试将声音效果添加到我在 Xcode 6 中制作的游戏应用程序中。这是我用来播放声音的代码:
var jumpSoundPlayer:AVAudioPlayer = AVAudioPlayer()
var jumpAudioPath:String = ""
var jumpSoundError: NSError? = nil
func setUpSoundPlayers(){
jumpAudioPath = NSBundle.mainBundle().pathForResource("Jump", ofType: "mp3")!
jumpSoundError = nil
jumpSoundPlayer = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: jumpAudioPath), fileTypeHint: "mp3", error: &jumpSoundError)
}
func playJumpSound(volume:Float = 1){
jumpSoundPlayer.volume = volume
jumpSoundPlayer.play()
}
我可以播放声音,但似乎在当前播放完成之前它不会播放声音。我怎样才能让它同时播放多个声音并相互重叠?
此外,每次播放声音时,它都会稍微降低帧速率。有办法解决吗?
【问题讨论】: