AVAudioPlayerNode 在停止和重新启动时跳过了很多声音。
创始人
2024-11-12 21:30:21
0

当AVAudioPlayerNode停止和重新启动时跳过声音的问题通常是由于调用了scheduleBuffer方法多次导致的。为了解决这个问题,我们可以使用以下方法:

  1. 定义一个布尔变量isPlaying来跟踪音频播放状态。
var isPlaying = false
  1. 在启动音频播放之前,检查isPlaying变量的值,如果为true则返回。
if isPlaying {
    return
}
  1. 在开始播放之前,先停止播放器。
playerNode.stop()
  1. 使用scheduleBuffer方法播放音频。
let audioFile = try! AVAudioFile(forReading: url)
let audioBuffer = AVAudioPCMBuffer(pcmFormat: audioFile.processingFormat, frameCapacity: AVAudioFrameCount(audioFile.length))
try! audioFile.read(into: audioBuffer)
playerNode.scheduleBuffer(audioBuffer, completionHandler: nil)
  1. 在播放音频后将isPlaying变量设置为true。
isPlaying = true
  1. 在停止音频播放时将isPlaying变量设置为false,并停止播放器。
isPlaying = false
playerNode.stop()

这样,当AVAudioPlayerNode重新启动时,之前的声音将会被清除,并且不会跳过声音。

相关内容

热门资讯

透视能赢!德普之星app安卓版... 透视能赢!德普之星app安卓版破解版,wepoker私局代打,技法教程(真是是有挂)-哔哩哔哩1、完...
透视大厅!we-poker正规... 透视大厅!we-poker正规吗(透视)开挂辅助挂(原来真的有挂)-哔哩哔哩1、we-poker正规...
透视免费!hhpoker到底可... 透视免费!hhpoker到底可以辅助吗,wepoker透视有吗,演示教程(确实真的有挂)-哔哩哔哩运...
透视好友!wpk官网下载链接,... 透视好友!wpk官网下载链接,佛手在线大菠萝智能辅助器,积累教程(一直有挂)-哔哩哔哩1、佛手在线大...
透视线上!aapoker怎么选... 透视线上!aapoker怎么选牌(透视)开挂辅助神器(好像存在有挂)-哔哩哔哩1、aapoker怎么...
透视透视!HH平台挂,aapo... 透视透视!HH平台挂,aapoker透视脚本,指南教程(确实存在有挂)-哔哩哔哩1)aapoker透...
透视安卓版本!wepoker俱... 透视安卓版本!wepoker俱乐部辅助(透视)开挂辅助插件(确实真的有挂)-哔哩哔哩1.wepoke...
透视规律!德普辅助器怎么用,w... 透视规律!德普辅助器怎么用,wepokerplus到底是挂了吗,总结教程(一直存在有挂)-哔哩哔哩1...
透视黑科技!wepoker破解... 透视黑科技!wepoker破解器,有没有人wepoker,指引教程(原来真的是有挂)-哔哩哔哩1、有...
透视规律!wepoker怎么买... 透视规律!wepoker怎么买辅助(透视)开挂辅助插件(真是真的是有挂)-哔哩哔哩运wepoker怎...