ADC Home > Reference Library > Technical Q&As > QuickTime > Movie Basics >

What is SetMovieDefaultDataRef?

Q I can't find documentation for the SetMovieDefaultDataRef function. What does it do, and how do I use it?
A SetMovieDefaultDataRef is defined in Movies.h as:
pascal OSErr SetMovieDefaultDataRef(Movie theMovie, Handle dataRef, OSType dataRefType);

It allows you to control where data will be written to when added to a movie. For example, if a movie was loaded from a file, the default data reference is initialized to be the file from which the movie was loaded. This example will set the default data reference to be a handle in memory:

     OSErr ConvertGeneralMIDIToSoundTrack (void)
     {
          OSErr                              err = noErr;
          StandardFileReply                  reply;
          short                              refNum;
          long                               logicalEOF;
          Handle                             dataHandle = nil, tempHandle = nil;
          Movie                              theMovie = nil, tempMovie = nil;

          // Specify the General MIDI file to import
          StandardGetFilePreview (nil, 0, nil, &reply);
          if (reply.sfGood)
          {
               // Open the data fork and suck everything into a handle
               err = FSpOpenDF (&reply.sfFile, fsRdPerm, &refNum);
               err = GetEOF (refNum, &logicalEOF);
               dataHandle = NewHandleClear (logicalEOF);
               HLock (dataHandle);
               err = FSRead (refNum, &logicalEOF, *dataHandle);
               HUnlock (dataHandle);
               FSClose (refNum);

               // Create a new movie in memory, set its default data reference
               // to be a handle
               tempMovie = NewMovie (newMovieActive);
               tempHandle = NewHandleClear (4);
               SetMovieDefaultDataRef (tempMovie, tempHandle,
                    HandleDataHandlerSubType);
               DisposeHandle (tempHandle);

               // Paste the handled data into our movie
               err = PasteHandleIntoMovie (dataHandle, 'Midi', tempMovie, 0, nil);

               // Save the movie out to a flattened file
               StandardPutFile ("\pSave MIDI to:", "\pMIDI movie", &reply);
               if (reply.sfGood)
               {
                    theMovie = FlattenMovieData (tempMovie,
                         flattenAddMovieToDataFork, &reply.sfFile, 'TVOD',
                         smCurrentScript, createMovieFileDeleteCurFile);
               }
          }
          return err;
     }

This method works fine as long as you have enough memory, and don't want to save the movie to disk. To put data into a file, call this function in order to pass in an alias to the file as the data reference and rAliasType as the data reference type:

SetMovieDefaultDataRef (tempMovie, fileAlias, rAliasType);

[Mar 14 1997]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.