小编Nat*_*per的帖子

当我的应用程序在使用Swift时仍然播放其声音时,如何允许继续播放背景音乐

我创建了一个应用程序,我试图让用户在玩游戏的同时继续听他们的音乐,但每当他们点击"播放"并且发出游戏声音时它就会停止背景音乐.我正在使用Swift在iOS上进行开发.这是启动游戏声音的一段代码.

func playSpawnedDot() {
    var alertSound: NSURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("spawnDot", ofType: "mp3")!)!
    var error:NSError?
    audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
    audioPlayer.prepareToPlay()

    if volumeBool {
        audioPlayer.play()
    }
}
Run Code Online (Sandbox Code Playgroud)

audio mobile xcode ios swift

42
推荐指数
6
解决办法
3万
查看次数

标签 统计

audio ×1

ios ×1

mobile ×1

swift ×1

xcode ×1