AVAudioPlayer声音无法在我的iPhone上播放

时间:2019-07-28 16:21:05

标签: ios swift avaudioplayer

我正在尝试创建一个在单击按钮时具有一些示例声音的应用程序,但是该应用程序无法在我的iPhone上播放。

这是我的代码:

import AVFoundation

var audioPlayer: AVAudioPlayer?

let bombSound = Bundle.main.path(forResource: "bombCountdown", ofType: "mp3")

func startBombSound() {
        let url = URL(fileURLWithPath: bombSound!)

        do {
            audioPlayer = try AVAudioPlayer(contentsOf: url)
            audioPlayer?.play()
        } catch {
            print(error.localizedDescription)
        }
    }

代码会通过,但实际上不会播放声音

0 个答案:

没有答案
相关问题