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.
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());