Hi,
Version FMOD: 2.01.09
Version Unity: 2020.3.25f1
I followed the tutorial, and everything works fine in unity editor.
https://www.fmod.com/docs/2.00/unity/examples-programmer-sounds.html
My code of callback is like this:
[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
// Retrieve the user data
IntPtr stringPtr;
instance.getUserData(out stringPtr);
// Get the string object
GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
String key = stringHandle.Target as String;
switch (type)
{
case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
{
FMOD.MODE soundMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.NONBLOCKING;
var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
if (key.Contains("."))
{
FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
exinfo.cbsize = FMOD.MarshalHelper.SizeOf(typeof(FMOD.CREATESOUNDEXINFO));
exinfo.suggestedsoundtype = FMOD.SOUND_TYPE.MPEG;
var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(Application.streamingAssetsPath + "/" + key, soundMode, ref exinfo, out FMOD.Sound dialogueSound);
if (soundResult == FMOD.RESULT.OK)
{
parameter.sound = dialogueSound.handle;
parameter.subsoundIndex = -1;
Marshal.StructureToPtr(parameter, parameterPtr, false);
}
}
else
{
var keyResult = FMODUnity.RuntimeManager.StudioSystem.getSoundInfo(key, out FMOD.Studio.SOUND_INFO dialogueSoundInfo);
if (keyResult != FMOD.RESULT.OK)
{
break;
}
var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(dialogueSoundInfo.name_or_data, soundMode | dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out FMOD.Sound dialogueSound);
if (soundResult == FMOD.RESULT.OK)
{
parameter.sound = dialogueSound.handle;
parameter.subsoundIndex = dialogueSoundInfo.subsoundindex;
Marshal.StructureToPtr(parameter, parameterPtr, false);
}
}
break;
}
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
{
var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
var sound = new FMOD.Sound(parameter.sound);
sound.release();
break;
}
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
{
stringHandle.Free();
break;
}
}
return FMOD.RESULT.OK;
}
But when I build it to Android, I got this error and play failed:
Error: [FMOD] FMOD_OS_File_Open : fopen failed to open ‘jar:file:///data/app/com.xxx.xxx.trunk.debug-of2jlBnTOrtH4Ql-1j2uAQ==/base.apk!/assets/Voice/FromAzure/C4A94F9FB0F6A1A1C9CDBD50CF18E4AA.mp3’, errno = 2
I’m sure this file is exist, If anybody know resolve this problem, I would appreciate.
Thanks,