Creating Links with HREF Tracks

One peculiar trick you can do with text tracks is to use them to turn your movie into a set of time-based hyperlinks. The idea is that by adding a so-called “HREF track,” you can make portions of your movie act like an anchor tag in HTML—clicking the movie takes you to a specified web page.

How do I do that?

Creating an HREF track is virtually identical to creating a text track—it is a real text track, after all—with URLs as the text samples. To actually activate its special features, though, you have to rename the track to HREFTrack. Also, because the URLs are not meant to be seen, you typically want to hide them by calling setEnabled(false) on the track.

Assuming there is an array of URL Strings called URLS, you can make the previous lab’s movie linkable by adding the following code after the first text media has been inserted into its track:

// add HREF track Track hrefTrack = movie.addTrack (TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT, 0); // create media for this track Media hrefMedia = new TextMedia (hrefTrack, timeScale); handler = (TextMediaHandler) hrefMedia.getHandler( ); System.out.println ("Created HREF Media"); hrefMedia.beginEdits( ); for (int i=0; i<URLS.length; i++) { byte[ ] msgBytes = URLS[i].getBytes( ); QTPointer msgPoint = new QTPointer (msgBytes); // add sample handler.addTextSample (msgPoint, // text 0, // font number 14, // font size, QDConstants.bold, // style, QDColor.yellow, // fg color, QDColor.black, // bg color, QDConstants.teJustCenter,// ...

Get QuickTime for Java: A Developer's Notebook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.