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

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and 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
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.