Your log seems missing a lot of information.
You could refer to cocos/audio/android/AudioDecoder.cpp, there are many ALOGV, but I didn’t see them in your log. Did you build the prebuilt library in release mode?
Please try to use debug mode to ensure the log is entire.
edit:
I guess it’s 500ms because of amount of logs. I’ll try in release mode in just a sec.
edit2:
In release mode:
217ms without playing.
233ms with playing.
Dunno why it’s longer than before fix, but fair enough it’s still very fast.
Looks like fix is working! You’re the best!
I’ll make some more testing before releasing though.
I think it was indeed time for a refactoring!
I had to stop some of my projects just because of laggy audio (even with preload, using the new AudioEngine), and I was experience some lag issues at my app startupp because of preloading about 150 short ogg sounds.
I just applied the “patch”, and it does fix the lag issue.
So I will just cross my finger, and publish this to the store
As I said in my previous post, I just crossed my finger, updated the AudioEngine and submitted my game to the Google Play store.
So far, I have no crash and my game has been tested on more than 70 different devices, and more than 15 different android version, from 4.0.4 to 7.1.1.
I only had very good reviews so I guess we can say your patch is a success
Good job!
Edit: In fact I just received a report with a bunch of crashes…
Here si the exception description:
So… does anyone have a solution for playing multiple sounds at the same time? Like making a piano, when using AudioEngine you have 16 tracks limit. If your sample has 2-3 seconds of duration it’s easy to break that 16 sounds playing at the same time limit. There’s no such a limitation in SimpleAudioEngine.
You could pass a profile structure to AudioEngine::play2d.
/**
* Play 2d sound.
*
* @param filePath The path of an audio file.
* @param loop Whether audio instance loop or not.
* @param volume Volume value (range from 0.0 to 1.0).
* @param profile A profile for audio instance. When profile is not specified, default profile will be used.
* @return An audio ID. It allows you to dynamically change the behavior of an audio instance on the fly.
*
* @see `AudioProfile`
*/
static int play2d(const std::string& filePath, bool loop = false, float volume = 1.0f, const AudioProfile *profile = nullptr);
class EXPORT_DLL AudioProfile
{
public:
//Profile name can't be empty.
std::string name;
//The maximum number of simultaneous audio instance.
unsigned int maxInstances;
/* Minimum delay in between sounds */
double minDelay;
/**
* Default constructor
*
* @lua new
*/
AudioProfile()
: maxInstances(0)
, minDelay(0.0)
{
}
};
maxInstances indicates the max instances of sound could be played at the same time.
Currently, it should be less than or equal to 32.
You could also set the max instances by AudioEngine::setMaxAudioInstance(32) globally.
In that case, you doesn’t need to pass a profile structure every time.
@floboc, this is not related to AudioEngine, it’s probably an issue of SimpleAudioEngine.
BTW, if you’re using AudioEngine, why is there a crash in SimpleAudioEngine which uses Cocos2dxSound.java? Could you paste more about that crash stack?