Cocos2d - SimpleAudioEngine - iPhone 上不播放声音

发布于 2024-11-18 12:09:07 字数 285 浏览 3 评论 0原文

最近我在使用 CocosDenshion 播放音效时遇到问题。声音在 iPhone 模拟器上播放,但在我自己的设备上不播放。我不确定我做错了什么。当然,我检查了我的扬声器是否仍在工作,但在使用其他应用程序或 iPod 库时它们会工作。

我只使用这个简单的代码:

[[SimpleAudioEngine sharedEngine] playEffect:@"button.wav"];

我仔细检查了文件名,它确实是button.wav。

我希望有人能帮助我。

Recently I have a problem with playing my soundeffects using CocosDenshion. The sound is playing on the iPhone Simulator, but not on my own device. I am not sure what I am doing wrong. Off course I checked if my speakers are still working, but they do while using other apps or the iPod Library.

I just use this simple code:

[[SimpleAudioEngine sharedEngine] playEffect:@"button.wav"];

I double checked the name of the file and it indeed is button.wav.

I hope someone can help me out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

陪你到最终 2024-11-25 12:09:07

我最近遇到了同样的问题,我已经解决了。

我正在使用 Xcode 4.3.2,似乎有一个错误。
默认情况下,并非您添加(拖动)到项目的所有资源都会添加到目标。
添加资源时,请确保(除了选中将项目复制到目标复选框之外)还选中添加到目标复选框。

您可以通过单击目标图标来检查资源是否已添加到捆绑包中。在“构建阶段”选项卡中,检查声音文件是否包含在“复制捆绑资源”中。
如果没有,请手动添加它们(+添加目标)

I had the same problem recently and I've figured it out.

I' m using Xcode 4.3.2 and there seems to be a bug.
Not all resources you add (drag) to the project are by default added to the target.
When you add a resource, make sure that (apart from checking the copy items into destination checkbox) you also check the add to target checkbox.

You can check if the resources has been added to the bundle by clicking on the target icon. In the Build Phases tab, check if the sound files are included in the Copy Bundle Resources.
If not, add them manually (+add target)

只为一人 2024-11-25 12:09:07

您可以尝试在程序的某个较早时刻预加载音效,否则必须先加载音效才能播放。您可以创建一个初始屏幕场景,该场景是第一个场景并加载所有资源,然后过渡到第一个“实际”场景。

    SimpleAudioEngine *engine = [SimpleAudioEngine sharedEngine];
    [engine preloadEffect:@"Example-Sound.caf"];

You might try preloading the sound effects, at some earlier point in the program, as otherwise it has to load the sound effect before it can play it. You could create a splashScreen scene that is the first scene and loads all your assets and then transitions to the first "actual" scene.

    SimpleAudioEngine *engine = [SimpleAudioEngine sharedEngine];
    [engine preloadEffect:@"Example-Sound.caf"];
沒落の蓅哖 2024-11-25 12:09:07

不确定这里是否是这种情况,但您应该记住,如果您的文件名为“Button.wav”并且您要求playEffect:@“button.wav”< /code> 它将在模拟器上播放,但不会在设备上播放。发生这种效果是因为桌面上的文件系统不区分大小写,而 iOS 设备上则不然。

Not sure whether it is the case here, but you should keep in mind that if your file name is "Button.wav" and you are asking to playEffect:@"button.wav" it will play on simulator, but will not on the device. This effect takes place because filesystem on your desktop is case-insensative, and on iOS devices it is not.

冰之心 2024-11-25 12:09:07

我有同样的问题并在这里找到。但我自己解决它。
如果你为ipad重新安装ios。默认开关(音量上)默认为“静音音量”方法。也许我在静音时将其更改为“旋转”方法。导致所有cocos2d都无法播放声音了。所以我把方法调回来并关闭静音。然后 SimpleAudioEngine 就可以正常工作了。这是ios系统的bug。

I have the same problem and find here. But I fix it by myself.
If you reinstall ios for ipad. the default switch(upon the volume) is default as "mute volume" method. Maybe I change it to "rotation" method when it is mute. It lead to all cocos2d can't play sound any more. So I turn the method back and set mute off. And then SimpleAudioEngine works well. It is ios system's bug.

葬花如无物 2024-11-25 12:09:07

请务必检查您的音频文件本身。采样率为 441000 的单声道 16 位、未压缩波形应该“正常工作”。我建议从在线 Cocos2D 示例中获取示例 .wav(例如 Cowbell.wav)并尝试播放该文件。

Make sure to check your audio file itself. A Mono 16 Bit, Uncompressed wave with a sample rate of 441000 should 'just work'. I recommend grabbing a sample .wav from an online Cocos2D example, like the Cowbell.wav and try to play that file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文