如何修复线程1:EXC_BAD_ACCESS(code = 1,address = 0x58)xcode

问题描述 投票:-2回答:1

我正在尝试通过按钮播放某些声音文件,但按下按钮会引发此错误线程1:行上的EXC_BAD_ACCESS(代码= 1,地址= 0x58)

audioPlayer.play()

我一直在寻找可能的解决方案,但找不到与该错误相关的任何东西,我的代码功能在打印之前一直运行良好,这是我完整的代码。

import UIKit
import AVFoundation

class ViewController: UIViewController {

    var track: String? = nil
    var audioPlayer = AVAudioPlayer()

    @IBAction func heavyButton(_ sender: Any) {
        track = "H"
        print("heavy machine gun \(track!)")
        reproducirAudio(audio: track!)
        audioPlayer.play()
    }

    func reproducirAudio(audio: String) {
        do {
            print("entro a la funcion de reproducir")
            audioPlayer = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: audio, ofType: "mp3")!))
            audioPlayer.prepareToPlay()
        } catch {
            print(error)
        }
    }
}
ios swift avaudioplayer
1个回答
0
投票

我找到了一个解决方案,该解决方案适用于iOS13

© www.soinside.com 2019 - 2024. All rights reserved.