Problem with the Sound on android

HI,
i have developed my first ios game using cocos2d-x 3.0 and i ported it to Android, all things are right except the sound, the app doesn’t play the whole of a sound.
How to fix this problem on the android ( on iOS it didn’t occur).

Thanks for your time and consideration.

What sound format are you using for Android?

I found that I needed to use sox to produce different sound formats and rates for Android.

On iOS I use CAF and on Android I use OGG. At first I used MP3 for both, but found issues with Android’s SoundPool

@corytrese - This is a good tip. Right now I am using .mp3 for all platforms.

For Android I use

sox Bright.wav -r 16k -c 1 Bright.ogg

For iOS I use

afconvert -f caff -d LEI16@22050 Bright.wav

For Win32 I use

 sox Bright.wav -r 16k -b 16 -c 1 Bright.wav

I removed my paths to try to make the sox commands easier to read.

http://sox.sourceforge.net/

2 Likes

Additional hint. On Mac, to convert all WAV files in a folder, do this in terminal:

for file in *.wav; do afconvert -f caff -d LEI16@22050 -c 1 “$file”; done

Change the *.wav to whatever format your original samples are in, change the @22050 for quality.

Great solution. My problem case is a bit different – I have a single folder of source wav files, sorted by quality and required by different games game.

My sound file pre-processing application iterates the folder to export batch and bash files to process them (a long series of lines like the ones I posted, above.)

To make things really simple, that pre-processing application also generates a .cpp and .h file so the application that needs them can use them easily.

This way I don’t have to manually maintain a conversion script, and I can reprocess my files and generate the C++ implementation for a game. This way, I don’t have to maintain any defines for the sound filenames, the enumeration of sounds, or write my own pre-loading logic, it’s just generated based on game membership for a particular sound file.

My workflow is then as follows:

  1. add sound file to library, tag it for the games that need it
  2. run the pre-processor & commit script output
  3. run the re-generated conversion scripts (some on windows, some on the mac)
  4. commit the new C++ files / converted audio files

Tie that up into gradle and poof! Life is simple :wink:

1 Like

I have converted the MP3 sounds to ogg, but it doesn’t work ! :frowning:
I have this message:

Please help me :frowning:

you should preload the sound files prior to use

We are also working on a brand new sound engine for 3.3, stay tuned

@yagoub
Hi! I use wav for all my project, you can try this.
Android can play mp3 but when you play effect the sound will play in short time. I don’t know.
In window phone you have to play wav.
Hope this help

Thanks, i changed playEffect to playBackgroundMusic, and it works, but i’m afraid if this has performance issue because i have 50 sounds and i play one sound in the same time.

Did you preload the sounds though?

SimpleAudioEngine::sharedEngine()->preloadEffect(name of file);

1 Like

No, i didn’t.