Jump to content

Audio decoding in Android


jeancode
 Share

Recommended Posts

Hey everyone !

 

I would like to use 6 different musics in my game, each lasting 3 to 5 minutes. I'm using an audiosprite generated with https://github.com/tonistiigi/audiosprite, I end up with a 19~20MB file. And this is working pretty good with chrome / FF on my desktop. I'd say the decode time is about 6 to 8 seconds.

 

Today I tried to port my game on Android, using crosswalk, and testing it on a real device, which is pretty decent I think. (http://www.samsung.com/uk/consumer/mobile-devices/tablets/tabpro/SM-T520NZWABTU). It's running on Android 4.2 or 4.4, can't remember. The only flaw I've noticed (well except my main problem) is the game doesn't run on webGL for some reasons (I haven't checked from which Android version webGL is available yet)

 

Back on topic : I couldn't play the game because the device was trying to decode the audiosprite for like 1~1.5 minutes, ending up crashing / killing the app, because it couldn't do it in time (well that's a guess). I suppose Android has some sort of a check against a timeout loading or something like that. To be sure I tried using an audiosprite with only SFX on it, without any musics (the file was <1MB then), and it worked fine.

 

I wonder if it's actually possible to have so many audio files for a mobile game. I'm kinda concerned because I think my testing device is probably better than the average android device.

 

 

More infos about the audiosprite : it's using ffmpeg to convert/encode the files. I use standard settings i.e 128kbit/s bitrate and 44100 Samplerate. I tried both mono and stereo, oddly enough I didn't notice any difference in the file size, nor in the decode time. (But the rendering had a worse quality obviously)

Link to comment
Share on other sites

This is a HUGE issue for me too. I had the game wait till the audio finished decoding before starting and on the desktop it didn't take long but on a Moto G Xt1032 it took like a minute to decode a few megabytes of audio. I thought this was an issue with oggs but mp3s take a long time too. Maybe using wavs is an option but that would adding a big amount of megabytes only for sound. 

 

A partial solution I've found is to load only the sounds you know are gonna play for sure at the start of the game and then decode the rest while the game is running hoping they'll be ready on time. 

 

Now, sice FF and Chrome will happily stream mp3s and oggs and there are many sites that play music, isn't there a way to play sounds in phaser without waiting for the whole file to decode?

Link to comment
Share on other sites

Low level stuff, but you could use the AudioContext to create an empty sound buffer and populate it with your sound data, that way you can implement your data loading however you fancy - maybe you'll do it better than the browser.  There are streaming options with this, search for AudioMediaStreamTrack.

Link to comment
Share on other sites

That's interesting, I don't know how good it would work. I'm a bit scared performances wise, because I guess streaming will increase the CPU load, especially on older devices.

Anyway It's comforting to see I'm not the only one struggling with this. That would be interesting to have more inputs about this problem (maybe from rich too ?)

Link to comment
Share on other sites

Will you distribute this as a native Android app?

 

In that case you may wanna give the Cordova Media plugin a try. I used it about a year ago to play 2-4 mb MP3's and it made a huge difference on Android. Sounds load and play instantly like in a native app. I don't think it supports audiosprites though, but maybe there is another Cordova plugin based on it that does it.

Link to comment
Share on other sites

Jeancode, yes you're pushing it trying to get that size audio files to work on a mobile device.  There's no exact lmit, it's as simple as - the less ram and slower cpu then the lower your audio capability will be.   I've had lengthy decodes with xdk/crosswalk for plain html5 wrapping, you could try the cordova media plugin as suggested by fariazz.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...