📜  带有 swift 代码示例的程序音频

📅  最后修改于: 2022-03-11 15:01:01.584000             🧑  作者: Mango

代码示例1
guard let soundFileURL = Bundle.main.url(forResource: "TestSound",
                                         withExtension:"wav") else {
                                            print("URL not found")
                                            return
}

do {
    audioPlayer = try AVAudioPlayer(contentsOf: soundFileURL)
} catch let error {
    print("Failed to load the sound: \(error)")
}

audioPlayer?.prepareToPlay()