Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

adding wired actions to text track



I am trying to create a text track which sends a wired action when the text changes. The action is triggered by a frame loaded event and is targeting a Flash movie in a child movie track.

There are two actions which could be sent. The actionName parameter determines which one is included in a particular sample in the text track. The actions works as expected if I trigger it them from a sprite track using MouseEnter and MouseExit events. They do not work when included in the text track.

The text does display correctly in the movie. The actions work correctly when triggered by mouse events in a sprite track. Since all the parts seem to work, but the combination doesn't, I am suspecting the problem is in the code which adds the AtomContainer to the sample.

That code, which follows, does four things:
1. creates a QTPointer containing the text.
2. creates an AtomContainer with the action and target atoms.
3. appends the AtomContainer to the QTPointer containing the text.
4. adds a sample containing the QTPointer to the text track.

public String addTextToMedia ( String textToAdd, int requestedDuration,
String targetName,
String actionName ) throws Exception {
String responseTxt = "" ;


		try {
            // create the text pointer
            int txtSize = textToAdd.length();
            QTPointer textPntr = new QTPointer( txtSize + 2, true );

// copy the size info
byte[] tmpBytes = new byte[2];
tmpBytes[0] = (byte)( (txtSize >> 8) & 0xff );
tmpBytes[1] = (byte)( (txtSize >> 0) & 0xff );
textPntr.copyFromArray( 0, tmpBytes, 0, 2); // copy length bytes
// copy the text
tmpBytes = textToAdd.getBytes();
textPntr.copyFromArray( 2, tmpBytes, 0, txtSize); //


// if there is a target and an action, create the action container, then append it to the text pointer
if ( (targetName.length() > 0) && (actionName.length() > 0) ) {
AtomContainer textActionContainer = new AtomContainer();


// add action when text track frame is loaded
// note this is stretching the defined code - the SpriteAtom class doesn't directly
// generate the atom - but does act on it in useful ways,
SpriteAtom frameLoadedActions = new SpriteAtom( textActionContainer );
String testName = actionName.toLowerCase();
if ( testName.indexOf("play") == 0 ) {
/* set Flash track rate on text track frame loaded to start animation playing */
System.out.println(" start track " +targetName);
frameLoadedActions.addMovieRateAction( null,
StdQTConstants.kQTEventFrameLoaded ,
0, // which track of movie ( 0 to use name )
trackName, // track name ( set ID above to 0 to use)
1.0f); // track rate


} else if ( testName.indexOf("repeat") == 0 ) {
/* set Flash track frame on text track frame loaded to restart animation */
System.out.println(" restart track " +targetName);
frameLoadedActions.addFlashFrameLabelAction( null,
StdQTConstants.kQTEventFrameLoaded ,
0, // which track of movie ( 0 to use name )
trackName, // track name ( set ID above to 0 to use)
"talk"); // which frame label
} // which action


// pre-pend size and type
tmpBytes = textActionContainer.getBytes();
int actionSize = tmpBytes.length + 8; // make room for size and type
QTPointer tmpPntr = new QTPointer(actionSize, false);
// get header parts in big-endian order
int[] textExtenHeaderArray = new int[2];
textExtenHeaderArray[0] = EndianOrder.flipNativeToBigEndian32(actionSize);
textExtenHeaderArray[1] = EndianOrder.flipNativeToBigEndian32(
StdQTConstants.kQTEventFrameLoaded);
// copy header info to pointer
tmpPntr.copyFromArray(0, textExtenHeaderArray, 0, 2);
// copy the atom container
tmpPntr.copyFromArray(8, tmpBytes, 0, tmpBytes.length);


                // add action container to text pointer
                textPntr = new QTPointer( textPntr, tmpPntr );
            } // add actions to text pointer

// 14Nov05 hhm: add duration input - use movie if requested <= 0 //
int useDuration = 0;
if ( requestedDuration > 0 ) {
useDuration = requestedDuration;
} else { // duration parent movie
useDuration = myTextMedia.getTrack().getMovie().getDuration();
}


System.out.println("initial media duration = " + myTextMedia.getDuration());
QTHandle textHndl = new QTHandle( textPntr, 0, textPntr.getSize());


            ScrpSTElement textStyle = new ScrpSTElement();
            textStyle.setFont(QDFont.getFNum("Arial"));
            textStyle.setScriptSize(16);
            textStyle.setHeight(18);
            TextDescription textDesc = new TextDescription();
            textDesc.setBackgroundColor( QDColor.white );
            textDesc.setDefaultFontName( "Arial" );
            textDesc.setDefaultStyle( textStyle );
            textDesc.setDisplayFlags(StdQTConstants.dfClipToTextBox);

            myTextMedia.beginEdits();
			myTextMedia.addSample((QTHandleRef)textHndl,
                            0,textHndl.getSize(),				// entire container
                            useDuration,						// duration
                            textDesc, 						//
                            1, 								// one sample
                            1);								// self-contained

			myTextMedia.endEdits();

        } catch (Exception e) {
            responseTxt += e.toString();
			e.printStackTrace();
		} finally {
            return responseTxt;
        }
    }


Henry Martin Little Planet Learning, Inc. www.littleplanetlearning.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-java mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-java/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.