SetLoopPoints() of an Event?


(Charlie Gilchrist) #1

I am trying to play an event and set the loop points of that event in Unity . I want to set it in Samples so I get an accurate loop.

Is there a way to get a reference to a sound from an event so I can call setLoopPoints()?

I have been trying this. The music plays but it doesn’t loop even once :

public uint startTime = 850036;
public uint endTime = 4229770;
[FMODUnity.EventRef]
public string musicFMOD;
FMOD.Studio.EventInstance musicEvent;
FMOD.Studio.EVENT_CALLBACK callback;
// Use this for initialization
void Start () {
    musicEvent = FMODUnity.RuntimeManager.CreateInstance(musicFMOD);
    callback = new FMOD.Studio.EVENT_CALLBACK(MusicCallback);
    musicEvent.setCallback(callback, FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED);
    musicEvent.start();
}

public FMOD.RESULT MusicCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance eventInstance, System.IntPtr parameters)
{
    if(type == FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED)
    {
        FMOD.ChannelGroup group;
        FMOD.Channel channel;
        FMOD.Sound sound;
        musicEvent.getChannelGroup(out group);

        group.getChannel(0, out channel);

        channel.getCurrentSound(out sound);
        channel.setLoopCount(-1);
        sound.setLoopPoints(startTime, FMOD.TIMEUNIT.PCM, endTime, FMOD.TIMEUNIT.PCM);
        sound.setLoopCount(-1);
    }

    return FMOD.RESULT.OK;
}

(Cameron Baron) #2

Can you confirm that all the API calls in the callback return Result.OK?