Hi guys,
Could the AudioEngine be improved by adding a method to get the audio duration using the url apart from the audio’s id?
Currently to get the audio duration, its needed to play it to get the id and then with that id the duration we can obtained.
The current approach has some problems.
Many times users need know the audio duration to prepare a sequence of actions where some of them depends on an audio finish. Right now this cannot be done.
Also the current implementation does not works fine because doing play in a line and getting the duration on the next line, returns always .-1 due to the async approach of new audio engine. After call play, the sound wont be loaded for some frames and calling getDuration intermediately will fail. The drawback of the async load method could not be a problem if a preloading service will be available. So when the play is called the sound is available just on that frame and getDuration would work. Even thought there is a preloading implementation it seems its not working always.
In any case this wont help when only is needed to get the audio duration to create a sequence of actions.
So my humble suggestions are:
- Add a method to get the audio duration using the sound’s url. This will allow not to play the sound.
- Making the preloading mechanism work for audio assets.
Thank you all.
About Point one, I was debugging a bit it looks like there is a bug,
When on the audioEngine’s preload callback, a sound is played and then the getDuration is called,
the result is -1 even thought the audio is already loaded. The problem is on AudioEngine-win32.cpp
because player._audioCache->_duration has the right duration but player._ready is false. so always -1
is returned.
float AudioEngineImpl::getDuration(int audioID)
{
auto& player = _audioPlayers[audioID];
if(player._ready){
return player._audioCache->_duration;
} else {
return AudioEngine::TIME_UNKNOWN;
}
}