线程1:播放声音时,EXC

编程入门 行业动态 更新时间:2024-10-09 22:15:49
本文介绍了线程1:播放声音时,EXC_BAD_ACCESS(代码= 1,地址= 0x48)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每当我尝试将声音文件分配给变量时,我的应用程序就会崩溃.我已经仔细检查了我的声音文件名,但无法正常工作. 这是我的代码:

Whenever I try to assign a sound file to a variable my app crashes. I've double checked my sound file names, but I can't get it to work. Here is my code:

struct variables { static var randomCode = 0 static var timerCounter = 30 static var timer = Timer() static var explosion:AVAudioPlayer = AVAudioPlayer() static var defuseSound:AVAudioPlayer = AVAudioPlayer() } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. //Error occurs on the following line let explosionFile = Bundle.main.path(forResource: "explosion", ofType: ".mp3") let defuseFile = Bundle.main.path(forResource: "defused", ofType: ".mp3") do { try variables.explosion = AVAudioPlayer(contentsOf: URL(fileURLWithPath: explosionFile!)) try variables.defuseSound = AVAudioPlayer(contentsOf: URL(fileURLWithPath: defuseFile!)) } catch { print(error) }

推荐答案

已多次回答,将其分配给变量或常量时,AVAudioPlayer不再接受参数.

This was answered many times, the AVAudioPlayer doesnt take arguments anymore when assigning it to a variable or constant.

static var explosion : AVAudioPlayer? static var defuseSound : AVAudioPlayer? // OR static var explosion : AVAudioPlayer! = nil

更多推荐

线程1:播放声音时,EXC

本文发布于:2023-11-26 19:21:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   声音   EXC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!