Technical: QuickTime
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Track Names

Dispatch 2

Many 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.

Str255 name;
Handle h = NewHandle(0);
UserData ud = GetTrackUserData(theTrack);
   
if (GetUserData(ud, h, kUserDataName, 1) == noErr) {
  long nameLength = GetHandleSize(h);
  if (nameLength > 255)
    nameLength = 255;
  BlockMoveData(*h, &name[1], size);
  name[0] = size;
}
else
  name[0] = 0;
   
DisposeHandle(h);

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.

if (GetMovieIndTrackType(GetTrackMovie(theTrack), 2,
         mediaType, movieTrackMediaType) == nil) {
  // there is only one track of this media type,
  // so we don't need to add a number
  // to this track name.
}
else {
  // Since there's more than one track of this type,
  // let's add an index number to the track type
  // string we constructed above
  long mediaTypeIndex = 1;
  Str255 numberString;
   
  while (GetMovieIndTrackType(GetTrackMovie(theTrack),
      mediaTypeIndex, mediaType,movieTrackMediaType) != theTrack)
      mediaTypeIndex++;
   
  NumToString(mediaTypeIndex, numberString);
  trackName[++trackName[0]] = ' ';
  BlockMoveData(&numberString[1], &trackName[trackName[0] + 1], numberString[0]);
  trackName[0] += numberString[0];
}

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 Also

QuickTime 3 Reference - Movie Toolbox - UserData

Inside Macintosh: QuickTime

Change History

4/16/98 - jph - First published

Topics
Previous | Next