TweetFollow Us on Twitter

Modern Times

Volume Number: 20 (2004)
Issue Number: 5
Column Tag: Programming

QuickTime Toolkit

by Tim Monroe

Modern Times

Updating the QTShell Application Framework

Introduction

We began this series of articles by developing a simple C-based application called QTShell that runs on both Windows and Macintosh operating systems. QTShell can open and display QuickTime movies, and it supports the standard movie editing operations. Over the past several years, we've gradually tinkered with QTShell to add various capabilities. For instance, in an earlier article ("2001: A Space Odyssey" in MacTech, January 2001), we upgraded the Macintosh portions of the code to use the Navigation Services APIs instead of the Standard File Package APIs we used originally (and still use in our Windows code). This was an important step on the road to full Carbonization, which allowed QTShell to run natively on Mac OS X as well as on Mac OS 8 and 9. And in another article ("Event Horizon" in MacTech, May 2002), we saw how to switch to the Carbon event model of processing events.

In this article, I want to present several more enhancements to QTShell. The Navigation Services functions that it currently calls, NavGetFile and NavPutFile, are now deprecated; they still work just fine, but they are no longer recommended. By moving to the more modern APIs provided by Navigation Services 3.0, we can pave the way for support for Unicode filenames and for displaying the Save As dialog box as a sheet, as in Figure 1.


Figure 1: The Save As sheet

This is a nicer interface than the dialog box displayed by NavPutFile, which is shown in Figure 2.


Figure 2: The Save As dialog box

I also want to show how to convert QTShell to use the movie storage functions introduced in QuickTime 6. A movie storage container is simply any container that can be addressed using a data reference, for instance a file or a block of memory. Currently QTShell works only with files specified using file system specification records (of type FSSpec). In an earlier article ("Somewhere I'll Find You" in MacTech, October, 2000), however, we how to open local and remote movie files using NewMovieFromDataRef with file and URL data references. It would be nice to operate on all QuickTime movie data using a single set of APIs, and that's what the movie storage functions provide. Instead of calling OpenMovieFile and specifying a file using an FSSpec, we can call OpenMovieStorage and specify a storage container using a data reference. Then, when it's time to save changes to a movie, we can call UpdateMovieInStorage instead of UpdateMovieResource. And so on. To complement these storage APIs, QuickTime 6.4 introduced a large number of data reference utilities that can create data references from data of type FSSpec, CFString, FSRef, CFURL and a handful of other types.

The ultimate goal in moving to the new Navigation Services APIs and the movie storage APIs is to be able to expunge all traces of file system specification records from QTShell. The main problem with FSSpecs is that they cannot represent files with non-ASCII Unicode names or names longer than 63 characters. These other data types -- CFString, FSRef, and CFURL -- can easily represent Unicode filenames and very long filenames.

Unfortunately, the complete removal of FSSpec data values from QTShell and all the associated utilities files that our applications depend upon, on both Macintosh and Windows, would require an overhaul that is beyond the scope of this article. But we'll do enough of the groundwork that finally making the jump to an FSSpec-free application will not be too difficult.

File Selection

Let's begin by getting rid of our calls to NavGetFile and NavPutFile. Navigation Services 3.0 and later replace these functions with a handful of functions that allow greater control over the file-selection process. They allow us to display the file-saving dialog box as a sheet (as in Figure 1) and they support retrieving information about selected files in the form of an FSRef, which supports Unicode and long filenames.

Choosing a File to Open

Currently QTShell calls the NavGetFile function to display the standard file-opening dialog box, shown in Figure 3. NavGetFile handles everything involved in displaying the dialog box and handling user actions in the box. When it exits, it fills out a record of type NavReplyRecord that contains information about the selected file, if any.


Figure 3: The file-opening dialog box

In Navigation Services 3.0, this scheme was changed significantly but not enough to cause major upheavals in our existing source code. We still need to get the default options for the dialog box, but now we need to call NavGetDefaultDialogCreationOptions, not NavGetDefaultDialogOptions:

NavGetDefaultDialogCreationOptions(&myOptions);
myOptions.optionFlags -= kNavNoTypePopup;
myOptions.optionFlags -= kNavAllowMultipleFiles;
myOptions.modality = kWindowModalityAppModal;
myOptions.clientName = CFStringCreateWithPascalString(NULL, 
   gAppName, GetApplicationTextEncoding());

This departs from our existing code in several ways. First, the clientName field is a CFString, not a Pascal string. We can create that string from an existing Pascal string by calling CFStringCreateWithPascalString. Later we'll need to release the string like this:

CFRelease(myOptions.clientName);

The other interesting option is the modality field, which can take these values:

enum {
   kWindowModalityNone                  = 0,
   kWindowModalitySystemModal           = 1,
   kWindowModalityAppModal              = 2,
   kWindowModalityWindowModal           = 3
};

As you can see, we use the kWindowModalityAppModal constant, which causes the dialog box to prevent user interaction with all other windows in the application. A sheet would use the kWindowModalityWindowModal constant, which blocks user interaction with just one other window (the one the sheet is attached to).

Once we've set up the dialog box options, we create the dialog box by calling NavCreateGetFileDialog:

myErr = NavCreateGetFileDialog(&myOptions, NULL, 
      myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc,
      (void*)myOpenList, &myDialogRef);

This call however does not display the dialog box to the user. This gives us an opportunity to further customize the appearance of the dialog box by calling NavCustomControl (as we'll do in a few moments). Once we've customized the box to our liking, we show it to the user by calling NavDialogRun.

When NavDialogRun returns, we can call NavDialogGetReply to retrieve a NavReplyRecord record that contains information about the selected file. We then proceed as before by getting an FSSpec for the selected file, which we return to the caller. Listing 1 shows the new definition of QTFrame_GetOneFileWithPreview.

Listing 1: Eliciting a movie file from the user

QTFrame_GetOneFileWithPreview
OSErr QTFrame_GetOneFileWithPreview (short theNumTypes, 
      QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, 
      void *theFilterProc)
{
#if TARGET_OS_WIN32
   StandardFileReply            myReply;
#endif
#if TARGET_OS_MAC
   NavDialogRef                     myDialogRef = NULL;
   NavReplyRecord                  myReply;
   NavTypeListHandle            myOpenList = NULL;
   NavEventUPP                     myEventUPP = 
                           NewNavEventUPP(QTFrame_HandleNavEvent);
   NavDialogCreationOptions   myOptions;
#endif
   OSErr                              myErr = noErr;
   
   if (theFSSpecPtr == NULL)
      return(paramErr);
   
   // deactivate any frontmost movie window
   QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), 
      false);
#if TARGET_OS_WIN32
   // prompt the user for a file
   StandardGetFilePreview((FileFilterUPP)theFilterProc, 
      theNumTypes, (ConstSFTypeListPtr)theTypeList,
      &myReply);
   if (!myReply.sfGood)
      return(userCanceledErr);
   
   // make an FSSpec record
   myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, 
         myReply.sfFile.parID, myReply.sfFile.name, 
         theFSSpecPtr);
#endif
#if TARGET_OS_MAC
   // specify the options for the dialog box
   NavGetDefaultDialogCreationOptions(&myOptions);
   myOptions.optionFlags -= kNavNoTypePopup;
   myOptions.optionFlags -= kNavAllowMultipleFiles;
   myOptions.modality = kWindowModalityAppModal;
   myOptions.clientName = CFStringCreateWithPascalString
                  (NULL, gAppName, GetApplicationTextEncoding());
   
   // create a handle to an 'open' resource
   myOpenList = (NavTypeListHandle)
         QTFrame_CreateOpenHandle(kApplicationSignature, 
            theNumTypes, theTypeList);
   if (myOpenList != NULL)
      HLock((Handle)myOpenList);
   
   // prompt the user for a file
   myErr = NavCreateGetFileDialog(&myOptions, NULL, 
         myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, 
         (void*)myOpenList, &myDialogRef);
   if ((myErr == noErr) && (myDialogRef != NULL)) {
      AEDesc                  myLocation = {typeNull, NULL};
   
      // if no open-file location exists, use ~/Movies
      if (QTFrame_GetCurrentFileLocationDesc(&myLocation, 
         kGetFileLoc) == noErr)
         NavCustomControl(myDialogRef, kNavCtlSetLocation, 
            (void *)&myLocation);   
      myErr = NavDialogRun(myDialogRef);
      if (myErr == noErr) {
         myErr = NavDialogGetReply(myDialogRef, &myReply);
         if ((myErr == noErr) && myReply.validRecord) {
            AEKeyword      myKeyword;
            DescType         myActualType;
            Size               myActualSize = 0;
            
            // get the FSSpec for the selected file
            if (theFSSpecPtr != NULL)
               myErr = AEGetNthPtr(&(myReply.selection), 1, 
                  typeFSS, &myKeyword, &myActualType, 
                  theFSSpecPtr, sizeof(FSSpec), &myActualSize);
            NavDisposeReply(&myReply);
         }
      }
      
       NavDialogDispose(myDialogRef);
   }
   
   // clean up
   if (myOpenList != NULL) {
      HUnlock((Handle)myOpenList);
      DisposeHandle((Handle)myOpenList);
   }
      
   if (myOptions.clientName != NULL)
      CFRelease(myOptions.clientName);
      
   DisposeNavEventUPP(myEventUPP);
#endif
 
   return(myErr);
}

Choosing a Filename to Save

The changes required to upgrade our existing file-selection routine QTFrame_PutFile are entirely analogous to those considered in the previous section. We need to replace NavPutFile by the combination of NavCreatePutFileDialog, NavDialogRun, NavDialogGetReply, and NavDialogDispose. There is only one "gotcha" here, and it's a big one: the FSSpec that we get when we call AEGetNthPtr no longer specifies the file we want to save the movie into (as it did with NavPutFile); rather, it specifies the directory that contains the file. I'm guessing that this was changed to better support values of type FSRef, which cannot specify non-existent files. The preferred way to respond to NavDialogGetReply is apparently to ask for the parent directory of the chosen filename in the form of an FSRef and then to create the file by calling FSRefCreateFileUnicode, which takes the parent directory and a Unicode filename. Since we are retaining our dependence on FSSpec values, we need to jump though a hoop or two.

What we need to do is find the directory ID of the parent directory returned to us, so that we can create an FSSpec record for the chosen file itself. Listing 2 shows some File Manager voodoo that accomplishes this.

Listing 2: Finding the directory ID of a file's parent directory

QTFrame_PutFile
myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS,
               &myKeyword, &myActualType, &myDirSpec, 
               sizeof(FSSpec), &myActualSize);
if (myErr == noErr)   {
   myFileName = NavDialogGetSaveFileName(myDialogRef);
   if (myFileName != NULL) {
      CInfoPBRec      myPB;
      myPB.dirInfo.ioVRefNum = myDirSpec.vRefNum;
      myPB.dirInfo.ioDrDirID = myDirSpec.parID;   
      myPB.dirInfo.ioNamePtr = myDirSpec.name;
      myPB.dirInfo.ioFDirIndex = 0;
      myPB.dirInfo.ioCompletion = NULL;
                   
      myErr = PBGetCatInfoSync(&myPB);
      if (myErr == noErr) {
         CFStringGetPascalString(myFileName, myString, 
                  sizeof(FSSpec), GetApplicationTextEncoding());
         myErr = FSMakeFSSpec(myPB.dirInfo.ioVRefNum, 
                  myPB.dirInfo.ioDrDirID, myString, &myMovSpec);
         if (myErr == fnfErr)
            myErr = noErr;
      }
      if (myErr == noErr)
         *theFSSpecPtr = myMovSpec;
   }
}

The trick here is to know that on entry to the PBGetCatInfoSync call, the ioDrDirID field should be set to the directory ID of the parent directory of the directory containing the chosen file, which is what is contained in the FSSpec returned by AEGetNthPtr; on exit that field will contain the directory ID of the directory itself (not its parent). Once we've retrieved that directory ID, we can then call FSMakeFSSpec to create an FSSpec for the file itself.

Showing the Save Changes Dialog Box

QTShell uses one other Navigation Services function, NavAskSaveChanges, in the Macintosh version of the QTFrame_DestroyMovieWindow function. We need to replace this with the newer NavCreateAskSaveChangesDialog. Listing 3 shows the key changed portions of QTFrame_DestroyMovieWindow.

Listing 3: Closing a movie window

QTFrame_DestroyMovieWindow   
if ((**myWindowObject).fIsDirty) {
   Str255                                 myString;
   NavAskSaveChangesAction         myAction;
   NavDialogCreationOptions      myOptions;
   NavUserAction                     myResult;
   NavEventUPP                        myEventUPP = 
                           NewNavEventUPP(QTFrame_HandleNavEvent);
   NavDialogRef                        myDialogRef = NULL;
   // get the title of the window
   GetWTitle(theWindow, myString);
      
   // install the application and document names
   NavGetDefaultDialogCreationOptions(&myOptions);
   myOptions.clientName = 
         CFStringCreateWithPascalString(NULL, gAppName, 
         GetApplicationTextEncoding());
   myOptions.saveFileName = 
         CFStringCreateWithPascalString(NULL, myString, 
         GetApplicationTextEncoding());      
   // specify the action
   myAction = gShuttingDown ? 
                        kNavSaveChangesQuittingApplication : 
                        kNavSaveChangesClosingDocument;
      
   // display the "Save changes" dialog box
   myErr = NavCreateAskSaveChangesDialog(&myOptions, 
            myAction, myEventUPP, NULL, &myDialogRef);
   if ((myErr == noErr) && (myDialogRef != NULL)) {
      myErr = NavDialogRun(myDialogRef);
      if (myErr == noErr) {
         myResult = NavDialogGetUserAction(myDialogRef);      
         switch (myResult) {
            case kNavUserActionSaveChanges:
               // save the data in the window
               QTFrame_UpdateMovieFile(theWindow);
               break;
                  
            case kNavUserActionCancel:
               // do not close the window, and do not quit the application
               gShuttingDown = false;
               return(false);
                  
            case kNavUserActionDontSaveChanges:
               // discard any unsaved changes (that is, don't do anything)
               break;
         }
      }
      
         NavDialogDispose(myDialogRef);
   }
      
   if (myOptions.clientName != NULL)
      CFRelease(myOptions.clientName);
      
   if (myOptions.saveFileName != NULL)
      CFRelease(myOptions.saveFileName);
         
   DisposeNavEventUPP(myEventUPP);
}

Setting the Default Location

Let's end this discussion by making sure that the directory displayed in the file opening and saving dialog boxes is a reasonable default. The Navigation Services functions will always display the most recent directory selected by the user when choosing a file to open or save into. This information is saved on a per-application and per-user basis, in the application's preference file. So, if a user saves a movie file on the Desktop, the next time he or she opens the file-saving dialog box, the Desktop will be the directory shown -- even if the user has quit the application and later relaunched it.

Our application doesn't need to create or read that preferences file explicitly because the Navigation Services functions take care of all that automatically. The only time that we might want to poke our noses into that file is when the user launches our application for the very first time. In that case, there will be no saved directory information. The default behavior of the Navigation Services APIs is to display the Documents folder in the user's home directory.

It's actually quite easy to change that default value to something more useful, perhaps the Movies folder in the user's home directory. To do this, we can use the Preferences APIs to read values out of the preferences file, which is called QTShell.plist and is stored in the Preferences folder that is inside of the Library folder in the user's home directory.

A preferences file is organized as a set of key-value pairs. The key is of type CFString and the value can be any Core Foundation property list type. Navigation Services maintains at least two items in that file, addressed using these keys:

AppleNavServices:PutFile:0:Path
AppleNavServices:GetFile:0:Path

The values associated with these keys are the locations of the directories most recently displayed in the file-saving and file-opening dialog boxes.

For present purposes, we don't need to read the values associated with those keys. Rather, all we need to do is determine whether a specific key exists in the preferences file. If it does, we'll let Navigation Services handle the setting of the directory displayed in the corresponding dialog box. But if one or the other of these keys does not have a value in the preferences file, we'll step in and set the location shown in the dialog box to the better default location, the Movies folder in the user's home directory. Listing 4 shows our definition of QTFrame_GetCurrentFileLocationDesc, which does this. We'll pass in one of these application-defined constants:

#define kPutFileLoc                     1
#define kGetFileLoc                     2

QTFrame_GetCurrentFileLocationDesc then calls CFPreferencesCopyAppValue to find the appropriate preference item. If it exists, we return paramErr to the caller to indicate that a preference item already exists for the specified dialog box. Otherwise we'll construct an AEDesc value for the desired folder and pass that back to the caller.

Listing 4: Setting the default file location

QTFrame_GetCurrentFileLocationDesc
#if TARGET_OS_MAC
OSErr QTFrame_GetCurrentFileLocationDesc
   (AEDescPtr theLocation, short theFileType)
{
   CFStringRef               myLocKey;
   CFPropertyListRef      myLoc;
   FSRef                        myFSRef;
   FSSpec                        myFSSpec;
   OSErr                        myErr = noErr;
   
   if (theLocation == NULL)
      return(paramErr);
      
   if (theFileType == kPutFileLoc)
      myLocKey = CFSTR("AppleNavServices:PutFile:0:Path");
   else
      myLocKey = CFSTR("AppleNavServices:GetFile:0:Path");
   // see whether our application's Preferences plist already contains a file location
   myLoc = CFPreferencesCopyAppValue(myLocKey, 
                              kCFPreferencesCurrentApplication);
   if (myLoc != NULL) {
      // there is an existing location
      CFRelease(myLoc);
      myErr = paramErr;
   } else {
      // there is no existing location; return a descriptor for ~/Movies
      myErr = FSFindFolder(kUserDomain, 
         kMovieDocumentsFolderType, kCreateFolder, &myFSRef);
      
      if (myErr == noErr)
         myErr = FSGetCatalogInfo(&myFSRef, kFSCatInfoNone,
                         NULL, NULL, &myFSSpec, NULL);
      if (myErr == noErr)
           myErr = AECreateDesc(typeFSS, &myFSSpec, 
                           sizeof(FSSpec), theLocation);
   }
   
   return(myErr);
}
#endif

All that remains is to call this function inside of QTFrame_GetOneFileWithPreview and QTFrame_PutFile. If you look back at Listing 3, you'll see these lines of code immediately preceding the call to NavDialogRun:

if (QTFrame_GetCurrentFileLocationDesc(&myLocation, 
            kGetFileLoc) == noErr)
   NavCustomControl(myDialogRef, kNavCtlSetLocation, 
            (void *)&myLocation);   

Movie Storage Functions

QuickTime 6.0 introduced a set of functions called the movie storage APIs. The fundamental idea here is dead simple: instead of being restricted to opening, updating, creating, and deleting movie files, we should be able to perform these operations on any containers that hold movie data. As you know, the most general means of picking out movie data is by using a data reference. Accordingly, the movie storage APIs allow us to operate on movie data using data references and their associated data handlers.

Let's consider an example. Our application currently opens a movie specified by a file system specification record by calling OpenMovieFile, like this:

myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdWrPerm);

If successful, OpenMovieFile returns a file reference number, which we use in all subsequent operations on the movie file. For instance, we can read the movie from that file using this code:

myErr = NewMovieFromFile(&myMovie, myRefNum, &myResID, 
               NULL, newMovieActive, NULL);

When we later want to save the user's changes to a movie, we call UpdateMovieResource, passing in the file reference number and the movie resource ID:

myErr = UpdateMovieResource(myMovie, 
   (**myWindowObject).fFileRefNum, 
   (**myWindowObject).fFileResID, NULL);

Using the new movie storage APIs, we can use OpenMovieStorage to open movie data specified by a data reference:

myErr = OpenMovieStorage(myDataRef, myDataRefType, 
      kDataHCanRead + kDataHCanWrite, &myDataHandler);

If successful, OpenMovieStorage returns an instance of a data handler, which we use in all subsequent operations on the movie container. For instance, we can save the user's changes to a movie using this code:

myErr = UpdateMovieInStorage(myMovie, 
      (**myWindowObject).fDataHandler);

Here's a list of the new movie storage APIs:

    CreateMovieStorage (replaces CreateMovieFile)

    OpenMovieStorage (replaces OpenMovieFile)

    NewMovieFromStorageOffset (replaces NewMovieFromFile)

    CloseMovieStorage (replaces CloseMovieFile)

    DeleteMovieStorage (replaces DeleteMovieFile)

    AddMovieToStorage (replaces AddMovieResource)

    PutMovieIntoStorage (replaces PutMovieIntoFile)

    UpdateMovieInStorage (replaces UpdateMovieResource)

    FlattenMovieDataToDataRef (replaces FlattenMovieData)

It's actually quite easy to upgrade QTShell to use these new functions. In this section, we'll see how to do this.

Maintaining Movie Storage Identifiers

First, as you probably have guessed from the snippet of code that calls UpdateMovieInStorage, we need to add a few fields to our window object record to keep track of the data reference, its type, and the data handler associated with the storage container.

typedef struct {
   WindowReference                fWindow;
   Movie                          fMovie;
   MovieController                fController;
   GraphicsImportComponent        fGraphicsImporter;      
   FSSpec                         fFileFSSpec;
   short                          fFileResID;
   short                          fFileRefNum;
   Boolean                        fCanResizeWindow;
   Boolean                        fIsDirty;
   Boolean                        fIsQTVRMovie;
   QTVRInstance                   fInstance;
   OSType                         fObjectType;
   Handle                         fAppData;
#if USE_DATA_REF_FUNCTIONS
   Handle                         fDataRef;
   OSType                         fDataRefType;
   DataHandler                    fDataHandler;
#endif
} WindowObjectRecord, *WindowObjectPtr, **WindowObject;

Notice that we use the compiler flag USE_DATA_REF_FUNCTIONS to conditionalize our code. This allows us to switch back to using the file-based functions if the need arises.

Opening a Movie

Perhaps the trickiest part of migrating to the movie storage functions is deciding how to open a movie storage container. Our file-based code calls OpenMovieFile and then NewMovieFromFile. So we might expect to call OpenMovieStorage and then NewMovieFromStorageOffset. But that's not quite right. NewMovieFromStorageOffset requires us to specify an offset to the movie atom within the storage container. In most cases we don't know what that offset is. Further, if we simply pass an offset of 0, we won't be able to open any QuickTime movie files that are not Fast Start files (where the movie atom is the first atom in the file). So we need a different strategy.

What seems to work is to call OpenMovieStorage and then NewMovieFromDataRef. Listing 5 shows a section of our revised version of QTFrame_OpenMovieInWindow.

Listing 5: Opening a movie

QTFrame_OpenMovieInWindow
#if USE_DATA_REF_FUNCTIONS
myErr = QTNewDataReferenceFromFSSpec(&myFSSpec, 0, 
               &myDataRef, &myDataRefType);
if (myErr != noErr)
   goto bail;
      
// ideally, we'd like read and write permission, but we'll settle for read-only permission
myErr = OpenMovieStorage(myDataRef, myDataRefType, 
               kDataHCanRead + kDataHCanWrite, &myDataHandler);
if (myErr != noErr)
   myErr = OpenMovieStorage(myDataRef, myDataRefType, 
               kDataHCanRead, &myDataHandler);
      
// if we couldn't open the file with even just read-only permission, bail....
if (myErr != noErr)
   goto bail;
// now fetch the first movie from the file
myErr = NewMovieFromDataRef(&myMovie, newMovieActive, 
               &myResID, myDataRef, myDataRefType);
if (myErr != noErr)
   goto bail;
#else
// ideally, we'd like read and write permission, but we'll settle for read-only permission
myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdWrPerm);
if (myErr != noErr)
   myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdPerm);
// if we couldn't open the file with even just read-only permission, bail....
if (myErr != noErr)
   goto bail;
// now fetch the first movie from the file
myResID = 0;
myErr = NewMovieFromFile(&myMovie, myRefNum, &myResID, 
               NULL, newMovieActive, NULL);
if (myErr != noErr)
   goto bail;
#endif

Then we need to save the movie storage identifiers in our window object record, like this:

#if USE_DATA_REF_FUNCTIONS
   (**myWindowObject).fDataRef = myDataRef;
   (**myWindowObject).fDataRefType = myDataRefType;
   (**myWindowObject).fDataHandler = myDataHandler;
#endif

Saving Changes to a Movie

To save a user's changes to a movie back into its storage container, we can call UpdateMovieInStorage. Listing 6 shows the lines we've altered in the function QTFrame_UpdateMovieFile.

Listing 6: Updating a movie's storage

QTFrame_UpdateMovieFile
#if USE_DATA_REF_FUNCTIONS
if ((**myWindowObject).fDataHandler == NULL)      
   myErr = QTFrame_SaveAsMovieFile(theWindow);
else   
   myErr = UpdateMovieInStorage(myMovie,
                  (**myWindowObject).fDataHandler);
#else
if ((**myWindowObject).fFileRefNum == kInvalidFileRefNum)
   myErr = QTFrame_SaveAsMovieFile(theWindow);
else   
   myErr = UpdateMovieResource(myMovie, 
               (**myWindowObject).fFileRefNum, 
               (**myWindowObject).fFileResID, NULL);
#endif

Closing a Movie

When we're finished working with a movie, we can close it by calling CloseMovieStorage. We also need to dispose of the data reference and the data handler instance associated with the movie. Listing 7 shows the changed lines in the function QTFrame_CloseWindowObject.

Listing 7: Closing a movie

QTFrame_CloseWindowObject
#if USE_DATA_REF_FUNCTIONS
if ((**theWindowObject).fDataHandler != NULL) {
   CloseMovieStorage((**theWindowObject).fDataHandler);
   CloseComponent((**theWindowObject).fDataHandler);
   (**theWindowObject).fDataHandler = NULL;
}
   
if ((**theWindowObject).fDataRef != NULL) {
   DisposeHandle((**theWindowObject).fDataRef);
   (**theWindowObject).fDataRef = NULL;
}
#else
// close the movie file
if ((**theWindowObject).fFileRefNum != kInvalidFileRefNum) {
   CloseMovieFile((**theWindowObject).fFileRefNum);
   (**theWindowObject).fFileRefNum = kInvalidFileRefNum;
}
#endif

Conclusion

Part of the price of delivering a modern QuickTime application is the inevitable need to continually upgrade its underpinnings as the operating system and user interface APIs evolve, or indeed as QuickTime itself evolves. In this article, we've seen how to use the currently recommended functions for selecting files and for opening and operating on movie data. The next step, which we have not taken here, would be to systematically replace all uses of the FSSpec data type by uses of the FSRef data type. This would give us a thoroughly modern application capable of opening movie files with Unicode or very long filenames.


Tim Monroe is a member of the QuickTime engineering team at Apple. You can contact him at monroe@mactech.com. The views expressed here are not necessarily shared by his employer.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.