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

Ableton Live 11.3.11 - Record music usin...
Ableton Live lets you create and record music on your Mac. Use digital instruments, pre-recorded sounds, and sampled loops to arrange, produce, and perform your music like never before. Ableton Live... Read more
Affinity Photo 2.2.0 - Digital editing f...
Affinity Photo - redefines the boundaries for professional photo editing software for the Mac. With a meticulous focus on workflow it offers sophisticated tools for enhancing, editing and retouching... Read more
SpamSieve 3.0 - Robust spam filter for m...
SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering. SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more
WhatsApp 2.2338.12 - Desktop client for...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
Fantastical 3.8.2 - Create calendar even...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event details... Read more
iShowU Instant 1.4.14 - Full-featured sc...
iShowU Instant gives you real-time screen recording like you've never seen before! It is the fastest, most feature-filled real-time screen capture tool from shinywhitebox yet. All of the features you... Read more
Geekbench 6.2.0 - Measure processor and...
Geekbench provides a comprehensive set of benchmarks engineered to quickly and accurately measure processor and memory performance. Designed to make benchmarks easy to run and easy to understand,... Read more
Quicken 7.2.3 - Complete personal financ...
Quicken makes managing your money easier than ever. Whether paying bills, upgrading from Windows, enjoying more reliable downloads, or getting expert product help, Quicken's new and improved features... Read more
EtreCheckPro 6.8.2 - For troubleshooting...
EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more
iMazing 2.17.7 - Complete iOS device man...
iMazing is the world’s favourite iOS device manager for Mac and PC. Millions of users every year leverage its powerful capabilities to make the most of their personal or business iPhone and iPad.... Read more

Latest Forum Discussions

See All

Motorsport legends NASCAR announce an up...
NASCAR often gets a bad reputation outside of America, but there is a certain charm to it with its close side-by-side action and its focus on pure speed, but it never managed to really massively break out internationally. Now, there's a chance... | Read more »
Skullgirls Mobile Version 6.0 Update Rel...
I’ve been covering Marie’s upcoming release from Hidden Variable in Skullgirls Mobile (Free) for a while now across the announcement, gameplay | Read more »
Amanita Design Is Hosting a 20th Anniver...
Amanita Design is celebrating its 20th anniversary (wow I’m old!) with a massive discount across its catalogue on iOS, Android, and Steam for two weeks. The announcement mentions up to 85% off on the games, and it looks like the mobile games that... | Read more »
SwitchArcade Round-Up: ‘Operation Wolf R...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 21st, 2023. I got back from the Tokyo Game Show at 8 PM, got to the office here at 9:30 PM, and it is presently 11:30 PM. I’ve done what I can today, and I hope you enjoy... | Read more »
Massive “Dark Rebirth” Update Launches f...
It’s been a couple of months since we last checked in on Diablo Immortal and in that time the game has been doing what it’s been doing since its release in June of last year: Bringing out new seasons with new content and features. | Read more »
‘Samba De Amigo Party-To-Go’ Apple Arcad...
SEGA recently released Samba de Amigo: Party-To-Go () on Apple Arcade and Samba de Amigo: Party Central on Nintendo Switch worldwide as the first new entries in the series in ages. | Read more »
The “Clan of the Eagle” DLC Now Availabl...
Following the last paid DLC and free updates for the game, Playdigious just released a new DLC pack for Northgard ($5.99) on mobile. Today’s new DLC is the “Clan of the Eagle" pack that is available on both iOS and Android for $2.99. | Read more »
Let fly the birds of war as a new Clan d...
Name the most Norse bird you can think of, then give it a twist because Playdigious is introducing not the Raven clan, mostly because they already exist, but the Clan of the Eagle in Northgard’s latest DLC. If you find gathering resources a... | Read more »
Out Now: ‘Ghost Detective’, ‘Thunder Ray...
Each and every day new mobile games are hitting the App Store, and so each week we put together a big old list of all the best new releases of the past seven days. Back in the day the App Store would showcase the same games for a week, and then... | Read more »
Urban Open-World RPG ‘Project Mugen’ Fro...
Last month, NetEase Games revealed a new free to play open world RPG tentatively titled Project Mugen for mobile, PC, and consoles. I’ve liked the setting and aesthetic since its first trailer, and today’s new video has the Game Designer and... | Read more »

Price Scanner via MacPrices.net

Apple AirPods 2 with USB-C now in stock and o...
Amazon has Apple’s 2023 AirPods Pro with USB-C now in stock and on sale for $199.99 including free shipping. Their price is $50 off MSRP, and it’s currently the lowest price available for new AirPods... Read more
New low prices: Apple’s 15″ M2 MacBook Airs w...
Amazon has 15″ MacBook Airs with M2 CPUs and 512GB of storage in stock and on sale for $1249 shipped. That’s $250 off Apple’s MSRP, and it’s the lowest price available for these M2-powered MacBook... Read more
New low price: Clearance 16″ Apple MacBook Pr...
B&H Photo has clearance 16″ M1 Max MacBook Pros, 10-core CPU/32-core GPU/1TB SSD/Space Gray or Silver, in stock today for $2399 including free 1-2 day delivery to most US addresses. Their price... Read more
Switch to Red Pocket Mobile and get a new iPh...
Red Pocket Mobile has new Apple iPhone 15 and 15 Pro models on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide service using all the major... Read more
Apple continues to offer a $350 discount on 2...
Apple has Studio Display models available in their Certified Refurbished store for up to $350 off MSRP. Each display comes with Apple’s one-year warranty, with new glass and a case, and ships free.... Read more
Apple’s 16-inch MacBook Pros with M2 Pro CPUs...
Amazon is offering a $250 discount on new Apple 16-inch M2 Pro MacBook Pros for a limited time. Their prices are currently the lowest available for these models from any Apple retailer: – 16″ MacBook... Read more
Closeout Sale: Apple Watch Ultra with Green A...
Adorama haș the Apple Watch Ultra with a Green Alpine Loop on clearance sale for $699 including free shipping. Their price is $100 off original MSRP, and it’s the lowest price we’ve seen for an Apple... Read more
Use this promo code at Verizon to take $150 o...
Verizon is offering a $150 discount on cellular-capable Apple Watch Series 9 and Ultra 2 models for a limited time. Use code WATCH150 at checkout to take advantage of this offer. The fine print: “Up... Read more
New low price: Apple’s 10th generation iPads...
B&H Photo has the 10th generation 64GB WiFi iPad (Blue and Silver colors) in stock and on sale for $379 for a limited time. B&H’s price is $70 off Apple’s MSRP, and it’s the lowest price... Read more
14″ M1 Pro MacBook Pros still available at Ap...
Apple continues to stock Certified Refurbished standard-configuration 14″ MacBook Pros with M1 Pro CPUs for as much as $570 off original MSRP, with models available starting at $1539. Each model... Read more

Jobs Board

Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple 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
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Retail Key Holder- *Apple* Blossom Mall - Ba...
Retail Key Holder- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 03YM1 Job Area: Store: Sales and Support Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.