Music loop problem

Music loop problem
0.0 0

#1

Hi all,

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…

Best regards,
Zsolt


#2

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.


#3

Same problem with MP3 format

i just adjust bgm by fadein & fadeout to make feeling better


#4

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?

Best regards,
Zsolt


#5

@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.


#6

Yes, exactly. Browsers (desktop/mobile) can loop the music without any problem. Only native builds have that gap…


#7

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.


#8

Absolutely. I will ask a member of our engineering team to review this thread.


#9

Many thanks! :slight_smile:


#10

got it, so what format is make scene?
thanks :smiley:


#11

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.


#12

well…
i am not making H5 game :sweat_smile:
i building game is for native,

the MP3 format, Infinite loop way,
it is normal operation in the iOS system,
but there will be intermittent on Android…


#13

hmm. I think I should try making an iOS build one of these days.


#14

Is there any progress with this issue?


#15

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.

Best regards,
Zsolt


#16

Let me them for help.


#17

I will ask @dumganhar :joy:


#18

Any news? I really need this feature to loop 5-10 secs long musics, it is impossible to do fade in/out.


#19

I will ping @dumganhar and ask him to review this thread.


#20

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.

void UrlAudioPlayer::setLoop(bool isLoop)
{
    _isLoop = isLoop;

    SLboolean loopEnable = _isLoop ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE;
    SLresult r = (*_seekItf)->SetLoop(_seekItf, loopEnable, 0, SL_TIME_UNKNOWN);
    SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::setLoop %d failed", _isLoop ? 1 : 0);
}

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}
};