i’m currently using FMOD on an iOS project and i want to use a callback to determine if the event playing reaches a certain marker. i’ve looked at the music callback example but it shows every type of callback plus bank creation and event triggering. it’s confusing trying to sort out what’s really needed just for this particular callback. can you give a simple example of how to use the FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_MARKER without all the extra code?
basically what i want to do is to wait a couple of seconds until the sound is paused before stopping the event. i figure i can do this by checking if the event has encountered a marker on the Timeline but i’m not certain. any help appreciated!
All you have to do is register your callback using Studio::EventInstance::setCallback…
// After creating the event instance, register the marker callback
instance->setCallback(MarkerCallback, FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_MARKER);
Then in your callback, just check for type FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_MARKER…
FMOD_RESULT F_CALLBACK MarkerCallback(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, FMOD_STUDIO_EVENTINSTANCE* event, void* parameters)
{
// Cast event instance to C++ type
FMOD::Studio::EventInstance* instance = (FMOD::Studio::EventInstance*)event;
if (type == FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_MARKER)
{
// Stop this instance when it reaches the timeline marker
instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT);
}
return FMOD_OK;
}
Your callback also receives some info about the name and position of the timeline marker, via the ‘parameters’ argument. Cast this to a pointer to a FMOD_STUDIO_TIMELINE_MARKER_PROPERTIES structure. For example, if your event has several markers, you could check the name for the one you’re interested in…
FMOD_RESULT F_CALLBACK MarkerCallback(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, FMOD_STUDIO_EVENTINSTANCE* event, void* parameters)
{
// Cast event instance to C++ type
FMOD::Studio::EventInstance* instance = (FMOD::Studio::EventInstance*)event;
if (type == FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_MARKER)
{
// Obtain the timeline marker properties
FMOD_STUDIO_TIMELINE_MARKER_PROPERTIES* props = (FMOD_STUDIO_TIMELINE_MARKER_PROPERTIES*)parameters;
// Stop this instance when it reaches the specially named marker
if (strcmp(props->name, "Stopper") == 0)
{
instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT);
}
}
return FMOD_OK;
}
The documentation for FMOD_STUDIO_EVENT_CALLBACK_TYPE has detailed information about how the ‘parameters’ argument works for each callback type: