3

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.

Guru
  • 21,652
  • 10
  • 63
  • 102

5 Answers5

9

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)

Marc Denessen
  • 201
  • 2
  • 4
4

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"];
tustvold
  • 148
  • 7
1

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.

Zapko
  • 2,461
  • 25
  • 30
0

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.

zszen
  • 1,428
  • 1
  • 14
  • 18
0

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.

haysclark
  • 1,080
  • 8
  • 16