How to get the name of the audio file

Originally I tried this with callbacks and it worked with the event.
private static FMOD.RESULT OnMusicPlayed(EVENT_CALLBACK_TYPE type, IntPtr _event, IntPtr parameters)
{
FMOD.Sound sound = new(parameters);
sound.getName(out string name, 1024);
Notification.ShowMessageDebug($“Playing: {name}”);
return FMOD.RESULT.OK;
}

I do find events too dangerous to implement as how they got implemented.
I need to fetch 2 events from FMOD.
One is when it stopped. Which I solved with music.getPlaybackState(out PLAYBACK_STATE state);

The other one would be to get the name.
Can I also fetch the name, just after music.start();
It is inside a mutli instrument and I would like to get the name of the audio file.

Fundamentally, the “best” way to do this is to use callbacks, as they’ll will be fired directly from the FMOD system, but what you’re doing for the playback state will work fine as well.

The only way to do this is using a callback - FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED will give you access to the sound being played by a multi instrument when it is about to play. The code you posted is relatively close to what I might do:

[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT GetSoundNameCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
    if (type == FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED)
    {
        FMOD.Sound sound = new(parameterPtr);
        int nameLength = 64; // use whatever length you require
        sound.getName(out string name, nameLength);
        UnityEngine.Debug.Log("sound name = " + name);
    }
    return FMOD.RESULT.OK;
}

If you run into any issues with that, please let me know.