AVAudioPlayer produces lag despite prepareToPlay() in Swift

后端 未结 3 1160
情话喂你
情话喂你 2020-12-09 03:15

Playing a very short sound (~0.5s) produces a hiccup (like a lag) in my SpriteKit iOS game programmed in Swift. In other questions, I read that I should prepareToPlay(

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 03:58

    I ran into this same problem and played the sound in the backgroundQueue.

    This is a good example: https://stackoverflow.com/a/25070476/586204.

    let qualityOfServiceClass = QOS_CLASS_BACKGROUND
    let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
    dispatch_async(backgroundQueue, {
        audioPlayer.play()
    })
    

提交回复
热议问题