I have experienced a strange small gap in the looped background music of my games on Android platform. I used CC 1.6.2, but a few days before I upgraded to 1.8.1 and the bug is still there. All music are stored in OGG format. I checked the beginning and the end of the samples with GoldWave, everything seems to be OK. I tested it on several Android devices, all of them are affected. But it works fine using the Simulator.
Does anybody else experienced the same problem? What can I do to avoid this small gap in playback? It’s very annoying…
Yes, it is sound engine behaviour on Android - whatever format you will choose default engine always will have gap, some guys are trying cricket audion engine or fmod.
I can’t use fadein/fadeout, the music has to loop… For example when I have only a few a seconds long loop, fading would be very strange.
So, it’s an engine weakness, it has to be fixed in a future release. @slackmoehrle, would you be so kind as to ask the developer team about this issue?
@PZsolt27 I’ve only tried web builds on desktop and mobile Safari and Android 7.0 and up and have no problems looping seamlessly with OGG and M4A. Is this only happening for you when testing in a native app?
@RazgrizHsu MP3s will always have this problem as it’s a problem with the format itself.
I never tried building for native via CC. It’s a bit of work but you could try using Cordova to wrap a web build.
I’ve used Cordova before and it would have problems with the native audio plugin and just removing that plugin and using the normal webkit audio would work fine.
But honestly I don’t know how CC wraps it’s native app so maybe you’d be missing out on other native CC features.
You have to use M4A for Safari and OGG for all other browsers. Normally when having to use loops like music and background ambience I load then dynamically via code so the app doesn’t load unnecessary audio files.
For once shots like effects I just assign MP3s via properties in the editor since all browsers support MP3.
I’ve just tested CC 1.9.0, but it still cannot loop the music without that small gap. @slackmoehrle, did you ask the dev team? IMHO, it is VERY important.
I guess the file size of music is bigger than 128K bytes.
We use UrlAudioPlayer to play sound for big files. UrlAudioPlayer internal is really simple, just invoke OpenSLES API directly.
The gap is possible a bug inside Android OpenSLES API implementation.
You could change the threshold to make PCMAudioPlayer play sound, PCMAudioPlayer will decode an audio file totally once it is preloaded, which may take some time. But since your music is just 5-10 seconds, I think you could try this way.
HOW TO CHANGE THE THRESHOLD:
Find AudioPlayerProvider.cpp file, search
static AudioFileIndicator __audioFileIndicator[] = {
{"default", 128000}, // If we could not handle the audio format, return default value, the position should be first.
{".wav", 1024000},
{".ogg", 128000},
{".mp3", 160000}
};