Q: I have created a movie with the NewMovie
function. After adding the tracks and the media using the
NewMovieTrack and NewTrackMedia functions, I'm calling
BeginMediaEdits to start a media editing session. However,
BeginMediaEdits returns the -2050 badDataRefIndex error code. I have checked the movie, track and media, and all are
valid. What am I doing wrong?
A: What's happening is when you create a movie from
"nothing," as with NewMovie , the movie does not have a
containing data reference (for example, if you call
NewMovieFromFile , the containing data reference is an alias
to the movie file on disk). Therefore, when you attempt to
add sample data to the media with BeginMediaEdits , QuickTime
can't do this because there's no data reference. You can solve this
problem by specifying a data reference when you create your
media with the NewTrackMedia function. In the sample below,
we show how to create a handle data reference (you can get
away with specifying a 0-length handle for the reference).
Now, when BeginMediaEdits is called to begin the media
editing session, QuickTime will have a data reference to
write data to:
Listing 1. Creating a handle data
reference to pass to the NewTrackMedia
function.
OSType dataRefType;
Handle dataRef = nil;
Handle hMovieData = NewHandle(0);
// Construct the Handle data reference
err = PtrToHand( &hMovieData, &dataRef, sizeof(Handle));
theMedia = NewTrackMedia (theTrack,
VideoMediaType,
600, // pass an appropriate time scale
// for your media here
dataRef,
HandleDataHandlerSubType);
.
.
.
// clean up when we are done with the
// media editing session
DisposeHandle(hMovieData);
DisposeHandle(dataRef);
|
|
[Sep 05 2000]
|