I’m trying to figure out how to retrieve a sound total time. I’ve tested the following:
soundState = FMODUnity.RuntimeManager.CreateInstance(soundKey);
int len = 0;
Unfortunately, len value ends with the value of 0 - zero. Am I using the wrong method for the task?
EventDescription::getLength only works on events with a timeline parameter, does the event in question have a timeline parameter?
No, it does not. It’s good to know that the issue is there. The sound guy wants to keep it this way, so there may be sounds for Japanese VA, English VA.
What do you think? It would be better to try another way to retrieve a sound length, or another way for separating audio for localized versions?
If you want the length of a sound when it is played you can implement a callback on
FMOD_STUDIO_EVENT_CALLBACK_SOUND_PLAYED, which will give you the underlying
Sound object, on which you can call
Sound::getLength. We have an example of how to implement an event callback here: Timeline Callbacks
You would need to add the
FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED flag when calling
EventInstance::setCallback and then the callback would be something like this:
static FMOD.RESULT SoundCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, System.IntPtr instancePtr, System.IntPtr parameterPtr)
FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
FMOD.Sound sound = new FMOD.Sound(parameterPtr);
result = sound.getName(out string name, 256);
if (result != FMOD.RESULT.OK)
result = sound.getLength(out uint length, FMOD.TIMEUNIT.MS);
if(result == FMOD.RESULT.OK)
Debug.Log("Sound Played. Name: " + name + " Length: " + length);