Documentation Archive Developer
Search

ADC Home > Reference Library > Technical Q&As > QuickTime > Wired Movies and Sprites >

Intercepting QuickTime Wired Actions


Q: I'm using the kActionApplicationNumberAndString wired action in my QuickTime movie to send a number and a string to my running application. How can my application intercept this action and retrieve the number and string data?

A: You'll need to first use a movie controller action filter function to intercept the mcActionExecuteOneActionForQTEvent action. You associate a movie controller action filter function with a given movie controller by calling the MCSetActionFilterWithRefCon functions as shown in Listing 1.



MCActionFilterWithRefConUPP myFilterProcUPP;
myFilterProcUPP = NewMCActionFilterWithRefConProc(myFilterProcedure);
MCSetActionFilterWithRefCon(movieController,
                            myFilterProcUPP,
                            0);

Listing 1. Calling the MCSetActionFilterWithRefCon functions.



The filter function allows your application to filter individual actions which are about to be executed in response to a QuickTime event. The events are first sent to your filter function before the actions are executed. Return true from your filter function if you do not want the action to be executed, return false if you do want the action executed.

Once you've setup a custom action filter function, you will need to add code to your filter function to check for the mcActionExecuteOneActionForQTEvent action. Next, when you receive the mcActionExecuteOneActionForQTEvent action in your filter function you can examine the atoms associated with this action to see if the kActionApplicationNumberAndString action is about to be executed.

The parameter passed with the mcActionExecuteOneActionForQTEvent action is a ResolvedQTEventSpecPtr (see Movies.h). The type of action may be determined by parsing the atoms contained in the actionAtom field of this structure (refer to the Wired Movies API reference for more information on the various atoms contained here: <http://developer.apple.com/documentation/quicktime/qtdevdocs/RM/rmWiredRef.htm>).

The code snippet in listing 2 below shows how to access the parameters of the kActionApplicationNumberAndString action from a movie controller action filter function.



 QTAtom findChildAtomOfType(QTAtomContainer container,
                            QTAtom parentAtom,
                            QTAtomType typeToFind,
                            QTAtomID *foundID)
{
    QTAtom currentChild=NULL, nextChild=NULL;
    do
    {
        QTAtomType    atomType;
        QTAtomID      id;

        QTNextChildAnyType (container,
                           parentAtom,
                           currentChild,
                           &nextChild);
        if (nextChild != 0)
        {
            QTGetAtomTypeAndID(container,
                               nextChild,
                               &atomType,
                               &id);
             if (atomType == typeToFind)
             {
                 *foundID = id;
                 break;
             }
        }
        currentChild=nextChild;
    } while (nextChild != NULL);

    return nextChild;
}

pascal Boolean myFilterProcedure (
         MovieController theMC,
         short theAction,
         void *theParams,
         long theRefCon)
{
    Boolean isHandled = false;

    switch (theAction) {
        case mcActionExecuteOneActionForQTEvent:
        {
            short                   action;
            ResolvedQTEventSpecPtr  qtEventSpecPtr;
            QTAtomSpec              *thekActionAtom;
            QTAtom                  atomPtr;
            long                    dataSize, theAction;
            Ptr                     atomData = NULL;

            qtEventSpecPtr = (ResolvedQTEventSpecPtr)theParams;
                /* get the action atom */
            thekActionAtom = &qtEventSpecPtr->actionAtom;
            if (thekActionAtom != NULL)
            {
                /* the first child of the action atom is the action
                   type atom (kWhichAction), so let's get it... */
                QTNextChildAnyType(thekActionAtom->container,
                                     thekActionAtom->atom,
                                     0,
                                     &atomPtr);
                if (atomPtr != NULL)
                {
                    /* lock the atom container before accessing a leaf
                        atom's data */
                    QTLockContainer(thekActionAtom->container);
                    /* now get the actual data for this action atom */
                    QTGetAtomDataPtr(thekActionAtom->container,
                                     atomPtr,
                                     &dataSize,
                                     &atomData);
                    if (atomData != NULL)
                    {
                        BlockMove(atomData, &theAction, 4);
                        if (theAction == kActionApplicationNumberAndString)
                        {
                            /* got the ActionApplicationNumberAndString
                               action! */
                            QTAtom    actionParamAtom1,actionParamAtom2;
                            QTAtomID  id;
                            long      param1;
                            /* now let's get the parameter atoms */
                            actionParamAtom1 = findChildAtomOfType(
                                    thekActionAtom->container,
                                    thekActionAtom->atom,
                                    kActionParameter,
                                    &id);
                            if (actionParamAtom1)
                            {
                                /* got the first parameter: "long aNumber" */
                                /* now get the actual data for this parameter */
                                QTGetAtomDataPtr(thekActionAtom->container,
                                                 actionParamAtom1,
                                                 &dataSize,
                                                 &atomData);
                                if (atomData != NULL)
                                {
                                    param1 = (long)*atomData;
                                }
                                /* now get the second parameter:
                                   "Str255 aString" */
                                actionParamAtom2 = QTFindChildByID(
                                        thekActionAtom->container,
                                        thekActionAtom->atom,
                                        kActionParameter,
                                        id+1, /* we want the next
                                                 parameter atom */
                                        0);   /* don't care */
                                if (actionParamAtom2)
                                {
                                    /* now get the actual data for
                                       this parameter */
                                    QTGetAtomDataPtr(thekActionAtom->container,
                                                     actionParamAtom2,
                                                     &dataSize,
                                                     &atomData);
                                    /* atomData contains the string data... */
                                }
                              }
                            isHandled = true;
                        }
                    }
                    /* done accessing leaf atom's data */
                    QTUnlockContainer(thekActionAtom->container);
                }
            }
        }
        break;
        default:
            break;
    }    // switch (theAction)
    return(isHandled);
}

Listing 2. Intercepting wired actions in a filter function




[Nov 14 2001]