简体   繁体   English

SKAction playSoundFileNamed ERROR

[英]SKAction playSoundFileNamed ERROR

I am getting this error after about 80 shots of a laser using a controlled Timer Interval so it fires every 0.2 seconds. 我使用受控的定时器间隔大约80次激光拍摄后出现此错误,因此每0.2秒发光一次。

* Terminating app due to uncaught exception 'Failed to Load Resource', reason: 'Resource squish.mp3 can not be loaded' * First throw call stack: *由于未捕获的异常'无法加载资源'而终止应用程序,原因:'资源squish.mp3无法加载'*首先抛出调用堆栈:

Here is the code I use to play the sound and create the laser. 这是我用来播放声音和创建激光的代码。 squish.mp3 is an audio file that is played when an object is destroyed. squish.mp3是一个在销毁对象时播放的音频文件。 Can anyone help? 有人可以帮忙吗? Is SKAction not very good for playing sound? SKAction对播放声音不是很好吗?

SKAction *sound = [SKAction playSoundFileNamed:@"lazer.mp3" waitForCompletion:NO];
[self runAction:sound];
[self removeActionForKey:@"sound"];
SKSpriteNode *laser = [SKSpriteNode spriteNodeWithImageNamed:@"fire"];

I was running into the same problem and I think I have a solution, though I'm not sure. 我遇到了同样的问题,我想我有一个解决方案,但我不确定。 I haven't seen the same crash in a while though. 我有一段时间没有看到同样的崩溃。

Make a single SKAction that represents playing the laser sound, and reuse that object. 制作一个代表播放激光声音的SKAction ,并重复使用该对象。

I think playSoundFileNamed: is supposed to be smart about not re-loading the audio file from the file system every time it's used. 我认为playSoundFileNamed:应该是聪明的,不会在每次使用时从文件系统重新加载音频文件。 But the crash indicates that it does get reloaded, at least occasionally. 但崩溃表明它确实会重新加载,至少偶尔会重新加载。 Keeping an SKAction around to reuse means that the audio file is only loaded once. 保持SKAction重用意味着音频文件只加载一次。

Not sure why I didn't try this but I just replaced the sound file and it seems to have cured it. 不知道为什么我没有尝试这个,但我只是更换了声音文件,它似乎已经治愈了。 However, if there was an error with the audio file why did it play around 200 times before crashing. 但是,如果音频文件出错,为什么它在崩溃之前会播放大约200次。

I would use a more Apple-compatible format, like AAC ( .m4a ) for the sound file. 我会使用更像Apple兼容的格式,如AAC( .m4a )作为声音文件。 Apple doesn't take too kindly with .mp3 s. Apple对.mp3并不太友好。 However, I think the file can be a Microsoft .wav file 但是,我认为该文件可以是Microsoft .wav文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM