I have some code used to get the duration of an event from an audio table while in the editor. It worked in version 2.0 of the integration, but does not work in 2.1. Unity version 2021.1. Now it always returns length of zero.
Any help will be much appreciated, I barely got it working the first time as this is way outside my comfort zone, not even sure where to start now.
double GetClipDuration(string lineID,string cutsceneID){
string lineKey = cutsceneID + "/" + lineID;
double result = 0;
var dialogueInstance = FMODUnity.RuntimeManager.CreateInstance("event:/Dialogue");
//Forcibly pin key in memory and pass memory allocation to var
GCHandle stringHandle = GCHandle.Alloc(lineKey, GCHandleType.Pinned);
dialogueInstance.setUserData(GCHandle.ToIntPtr(stringHandle));
FMOD.Studio.SOUND_INFO dialogueSoundInfo;
string key = stringHandle.Target as String;
var keyResult = FMODUnity.RuntimeManager.StudioSystem.getSoundInfo(key, out dialogueSoundInfo);
Debug.Log("Checking key.");
if (keyResult != FMOD.RESULT.OK)
{
Debug.Log("Key not found.");
return 0;
}
Debug.Log("Key found.");
FMOD.Sound dialogueSound;
FMOD.MODE soundMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.NONBLOCKING;
var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(dialogueSoundInfo.name_or_data, soundMode | dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);
Debug.Log("Creating sound.");
if (soundResult == FMOD.RESULT.OK)
{
//Get length
FMOD.Sound subSound;
dialogueSound.getSubSound(dialogueSoundInfo.subsoundindex, out subSound);
string n;
uint length = 0;
subSound.getLength(out length, FMOD.TIMEUNIT.MS);
Debug.Log("sound created with length: " + length);
result = length;
Debug.Log(result);
}
stringHandle.Free();
return result;
}