ADC Home > Reference Library > Technical Q&As > QuickTime > Movie Basics >

Using a QuickTime time base callback to detect when a movie has stopped


Q: I'm trying to use NewCallBack with callBackAtExtremes and triggerAtStop to detect when a Movie has stopped playing, but the QuickTime documentation doesn't say where to specifically set these flags. Depending on what flags I do use, NewCallBack sometimes returns NULL. How do you set up a callback function using callBackAtExtremes and triggerAtStop?

A: triggerAtStop is a flag passed to the CallMeWhen API as the param1 parameter when callBackAtExtremes was used as the cbType flag to NewCallBack. Listing 1 demonstrates how to set this up.

Listing 1.

// A generic callback function, installed by CallMeWhen.
// pascal void MyQTCallBackProc(QTCallBack cb, long refCon);

pascal void MyDoSomethingCallBack(QTCallBack cb, long refCon)
{
    MyAppDataPtr myStuff;

    if (NULL == refCon) return;
    myStuff = (MyAppDataPtr)refCon;
    myStuff->didSomething = true;

    return;
}

// Setting up a CallBack to fire using the callBackAtExtremes and
// triggerAtStop flags.
// MyDoSomethingCallBack function will be called when the time
// base has stopped.

OSErr SetUpTriggerAtStopCallBack(MyAppDataPtr inAppData)
{
    QTCallBack    theQTCallBack;
    QTCallBackUPP theCallBackUPP;

    OSErr err = paramErr;

    theQTCallBack = NewCallBack(GetMovieTimeBase(inAppData->myMovie),
                                callBackAtExtremes);
    if (theQTCallBack) {
        theCallBackUPP = NewQTCallBackUPP(MyDoSomethingCallBack);
        err = CallMeWhen(theQTCallBack, theCallBackUPP,
                         inAppData, triggerAtStop, 0, 0);
    }

    // save these so we can toss them later
    inAppData->myQTCallBack = theQTCallBack;
    inAppData->myCallBackUPP = theCallBackUPP;

    return err;
}

When done with the QTCallBack and QTCallBackUPP, remember to call DisposeCallBack and DisposeQTCallBackUPP.

References:


[Aug 12, 2003]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.