| Log In | Not a Member? |
Contact ADC
|
|
Track NamesDispatch 2Many applications need to display a list of the tracks contained in a movie. QuickTime provides the ability for applications to determine a user displayable name for each track in a movie. Using Apple's MoviePlayer application users can assign a name to a track in a movie. Some software that creates QuickTime movies may choose to assign names to the tracks as they are created. A Track's name is stored in the Track's UserData. If a Track has an assigned name, the following code will extract it into a Pascal string.
If a track doesn't have a name, we'd like to assign a name based on the media type of the track. If a movie contains a single sound track and a single video track we'd like them to be named "Sound" and "Video". If the movie contains one video track and two sound tracks, we'd like them to be named "Video", "Sound 1" and "Sound 2". To do this, we need to determine the media type of a track. We do this as shown below. OSType mediaType; Media theMedia = GetTrackMedia(theTrack); GetMediaHandlerDescription(theMedia, &mediaType, nil, nil); The media type returned by GetMediaHandlerDescription is a four character code which uniquely identifies the media. This is not intended to be displayed to the user. We can ask the media handler for the text of the media type. Str255 name; MediaHandler theMediaHandler = GetMediaHandler(theMedia); MediaGetName(theMediaHandler, name, 0, nil); Now we need to determine if there is more than one track with this media type. If there is, we need to determine the index of the current track so we can assign it a number.
This example has shown one way to use the information available from QuickTime about the movie to construct a track name. Of course, your application is free to use this information to construct any kind of track name that makes sense. If you want to assign a name to a track, you can use the following code. This code assumes that the Pascal string "name" has been filled in with the text you want to set the track name to. Also, note that this code first removes any existing track name before setting the new name. UserData ud = GetTrackUserData(theTrack); while (RemoveUserData(ud, kUserDataName, 1) == noErr) ; SetUserDataItem(ud, &name[1], name[0], kUserDataName, 0); See AlsoQuickTime 3 Reference - Movie Toolbox - UserData Change History4/16/98 - jph - First published |
|
Topics Previous | Next |