我是斯威夫特的新手。我正在尝试运行此代码但出现错误:
线程 1:EXC_BAD_ACCESS(代码=1,地址=0x48)
错误出现在这里:
self.player.play()
任何人都可以帮助解决这个问题吗?
导入 UIKit 导入 AVFoundationRun Code Online (Sandbox Code Playgroud)类视图控制器:UIViewController {
var player = AVAudioPlayer() override func viewDidLoad() { super.viewDidLoad() do { if let audioPath = Bundle.main.path(forResource: "music", ofType: "mp3") { try player = AVAudioPlayer(contentsOf: URL(fileURLWithPath: audioPath)) } } catch { print("ERROR") } self.player.play() }