Documentation Archive Developer
Search

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

Using Navigation Services to filter QuickTime files


Q: I'm using Navigation Services in my QuickTime-saavy application, and I'd like to be able to display in my Navigation Services Open dialog box all the files QuickTime is able to open. Is there any easy way to do this?

A: Yes. The QuickTime CanQuickTimeOpenFile function will tell you whether a file can be opened by QuickTime using a graphics importer or opened in place as a movie. Simply call this API from a Navigation Services application-defined filter function and you'll be able to display all files QuickTime is able to open. Here's a sample Navigation Services filter function which demonstrates how this is done:



 OSStatus    GetFSSpecFromAEDesc( FSSpec *fsspec, AEDesc* theItem )
{
    OSStatus    err           = noErr;
    AEDesc      coerceDesc    = { NULL, NULL };
    AEDesc      coerceDesc2   = { NULL, NULL };
    FSSpec      fsSpec;


    /* If the AEDesc isn't already an FSSpec, convert it to one... */
    if ( theItem->descriptorType != typeFSS )
    {
        err = AECoerceDesc( theItem, typeFSS, &coerceDesc2 );
        /* Get the FSSpec out of the AEDesc */
        if ( err == noErr )
        {
            theItem = &coerceDesc2;
        }
    }
    err = AEGetDescData( theItem, fsspec, sizeof(fsSpec) );
    AEDisposeDesc( &coerceDesc2 );

    return( err );
}

pascal Boolean NavLaunchServicesFilterProc(
                                          AEDesc* theItem,
                                          void* info,
                                          NavCallBackUserData ioUserData,
                                          NavFilterModes filterMode
                                          )
{
    #pragma unused(ioUserData)
    NavFileOrFolderInfo    *myInfo      = (NavFileOrFolderInfo *)info;
    OSStatus                err         = noErr;
    Boolean                 showItem    = false;
    FSSpec                  fsspec;
    if ( filterMode == kNavFilteringBrowserList )
    {
        if (theItem->descriptorType == typeFSS)
        {
            /* file or folder? */
            if (myInfo->isFolder)
            {
                /* show all folders */
                showItem = true;
            }
            else    /* we have a file, not a folder */
            {
                Boolean outCanOpenWithGraphicsImporter    = false;
                Boolean outCanOpenAsMovie        = false;
                err = GetFSSpecFromAEDesc( &fsspec, theItem );
                if ( err != noErr ) goto BailWithError;
/*
A reference to the documentation for the CanQuickTimeOpenFile function
is provided at the end of this document.

We simply pass an FSSpec for the file of interest, and QuickTime will return
to us in the outCanOpenWithGraphicsImporter and outCanOpenAsMovie parameters
a value indicating whether or not the file can be opened using a graphics
importer or in place as a movie.

Of particular interest are the various flags you can pass for the inFlags
parameter. These affect the way QuickTime performs its search. Here's a
list of the flags:

-inFlags Constants-

kQTDontUseDataToFindImporter
Tells QuickTime not to use the data in the file to help in the search.
This will speed up the search, especially in cases where a negative
result is returned, but it will cause QuickTime to report that it
cannot open files that aren't identified by a recognized file type
or file name suffix.

kQTDontLookForMovieImporterIfGraphicsImporterFound
Tells QuickTime to short-circuit its search as soon as it finds one
way to open the file. Pass this flag if you want to know whether a
file can be opened with a graphics importer or as a movie, but you
don't care which.

kQTAllowOpeningStillImagesAsMovies
Tells QuickTime to consider opening still images as movies. If
this flag is set, if a file can be opened using a graphics importer
QuickTime will automatically say it can be opened as a movie.

kQTAllowImportersThatWouldCreateNewFile
Tells QuickTime to include importers which would create new files.
If this flag is clear, QuickTime only includes importers which can
import in place without needing to create new files.

kQTAllowAggressiveImporters
Tells QuickTime to include movie importers for file types like PICT
and TEXT that aren't traditionally thought of as movies. If this
flag is clear, QuickTime excludes these movie importers.

We recommend using the kQTDontLookForMovieImporterIfGraphicsImporterFound
flag, as it makes the search faster, since you don't care how the file
is opened.  In certain situations if may be useful to use the
kQTDontUseDataToFindImporter flag, as it will also speed-up the
search. However, the drawback is it will skip files with no
suffix or file type.
*/
                err = CanQuickTimeOpenFile(
                       &fsspec,
                           /* fileType */
                       myInfo->fileAndFolder.fileInfo.finderInfo.fdType,
                           /* filename suffix, or 0 if not known */
                       0,
                           /* returns true if file can be opened with a
                           graphics importer */
                       &outCanOpenWithGraphicsImporter,
                           /* returns true if file can be opened with a
                           movie importer */
                       &outCanOpenAsMovie,
                           /* returns true if file can be opened both with
                           a graphics importer and movie importer, but
                           QT would prefer to use a graphics importer */
                       nil,
                           /* inFlags, we'll specify
                           kQTDontLookForMovieImporterIfGraphicsImporterFound
                           to tell QuickTime to short-circuit its search as
                           soon as it finds one way to open the file. We
                           don't care if the file can be opened with a
                           graphics importer or as a movie. */
                       kQTDontLookForMovieImporterIfGraphicsImporterFound
                       );
                if ( err != noErr ) goto BailWithError;
                if ((outCanOpenWithGraphicsImporter) || (outCanOpenAsMovie))
                {
                    /* success!! file can be opened with either a graphics
                    importer or movie importer */
                    showItem = true;
                }
            }
        }
    }
    return (showItem);
BailWithError:
    return( false );
}

Listing 1. Sample Navigation Services application-defined filter function which uses the CanQuickTimeOpenFile function to filter files



References:

Documentation for the CanQuickTimeOpenFile can found in the QuickTime online documentation at the address:
http://developer.apple.com/documentation/quicktime/qtdevdocs/APIREF/SOURCESI/canquicktimeopenfile.htm


[Jul 15 2002]