I have find an article from the apples's quicktime develop
center:http://developer.apple.com/qa/qa2004/qa1341.html
It is a Q&A:
Q: I can create a movie from a movie file using the |NewMovieFromFile|
API, but how do I create a movie from movie data which resides in memory?
I think this is what I need,but when I do it like the answer says,error
occurs;
The error is -2048 ,when I call the NewMovieFromDataRef.
Who can tell me why? Or is that answer right?
Help me please!!
You need to tag the DataRef correctly so QT knows what to do with the
data in memory. In the Q&A you mention there is a link to TN1195 which
discusses this in detail.
-- This message was sent from a personal account --
-- All views are mine and not necessarily shared by my employer --
------------------------------------------------------------------------
_And do like this ,but I it still return -2048(even I passed the file
name and the file type).If someone have enough time ,please try it, I do
not know what 's wrong it happend!
<http://developer.apple.com/technotes/tn/tn1195.html>_
It is my Code :
//////////
//
// PtrDataRef_AddFileNameExtension
//
// Tell the data handler to set
// the file name extension in the
// data reference.
//
//////////
/* set the data ref extension for the
data ref handler */
anErr = DataHSetDataRefExtension(
dataRefHandler, /* data ref. handler */
fileNameHndl, /* data ref. extension to add */
kDataRefExtensionFileName);
bail:
if (fileNameHndl)
/* no longer need this */
DisposeHandle(fileNameHndl);
return anErr;
}
//////////
//
// PtrDataRef_AddFileTypeExtension
//
// Tell the data handler to set
// the file type extension in the
// data reference.
//
//////////
OSStatus PtrDataRef_AddFileTypeExtension(
ComponentInstance dataRefHandler, /* data ref. handler */
OSType fileType) /* file type for extension */
{
Handle fileTypeHndl = NULL;
OSStatus anErr = noErr;
OSType myType;
/* set the data ref extension for the
data ref handler */
anErr = DataHSetDataRefExtension(
dataRefHandler, /* data ref. handler */
fileTypeHndl, /* data ref. extension to add */
kDataRefExtensionMacOSFileType);
bail:
if (fileTypeHndl)
/* no longer need this */
DisposeHandle(fileTypeHndl);
return anErr;
}
//////////
//
// PtrDataRef_AddMIMETypeExtension
//
// Tell the data handler to set
// the mime type extension in the
// data reference.
//
//////////
OSStatus PtrDataRef_AddMIMETypeExtension(
ComponentInstance dataRefHandler, /* data ref. handler */
StringPtr mimeType) /* mime type for extension */
{
OSStatus anErr = noErr;
Handle mimeTypeHndl = NULL;
/* set the data ref extension for the
data ref handler */
anErr = DataHSetDataRefExtension(
dataRefHandler, /* data ref. handler */
mimeTypeHndl, /* data ref. extension to add */
kDataRefExtensionMIMEType);
bail:
if (mimeTypeHndl)
/* no longer need this */
DisposeHandle(mimeTypeHndl);
return anErr;
}
//////////
//
// MyCreatePointerReferenceHandle
// Create a pointer data reference handle.
//
// The pointer data reference handle contains
// a record specifying a pointer to a block of
// movie data along with a size value.
//
//////////
// First create a data reference handle for our data
dataRef = MyCreatePointerReferenceHandle(data, dataSize);
if (!dataRef) goto bail;
// Get a data handler for our data reference
err = OpenADataHandler(
dataRef, /* data reference */
PointerDataHandlerSubType, /* data ref. type */
NULL, /* anchor data ref. */
(OSType)0, /* anchor data ref. type */
NULL, /* time base for data handler */
kDataHCanRead, /* flag for data handler usage */
&dataRefHandler); /* returns the data handler */
if (err) goto bail;
// We can add the filename to the data ref to help
// importer finding process. Find uses the extension.
// If we add a filetype or mimetype we must add a
// filename -- even if it is an empty string
if (fileName || fileType || mimeTypeString)
{
err = PtrDataRef_AddFileNameExtension(
dataRefHandler, /* data ref. handler */
fileName); /* file name for extension */
if (err) goto bail;
}
// The pointer data handler can also be told the
// filetype and/or MIME type by adding data ref
// extensions. These help the importer finding process.
// NOTE: If you add either of these, you MUST add
// a filename first -- even if it is an empty Pascal
// string. Any data ref extensions will be ignored.
// to add file type, you add a classic atom followed
// by the Mac OS filetype for the kind of file
if (fileType)
{
err = PtrDataRef_AddFileTypeExtension(
dataRefHandler, /* data ref. handler */
fileType); /* file type for extension */
if (err) goto bail;
}
// to add MIME type information, add a classic atom followed by
// a Pascal string holding the MIME type
if (mimeTypeString)
{
err = PtrDataRef_AddMIMETypeExtension (
dataRefHandler, /* data ref. handler */
mimeTypeString); /* mime string for extension */
if (err) goto bail;
}
/* dispose old data ref handle because
it does not contain our new changes */
DisposeHandle(dataRef);
dataRef = NULL;
/* re-acquire data reference from the
data handler to get the new
changes */
err = DataHGetDataRef(dataRefHandler, &dataRef);
return dataRef;
bail:
if (dataRef)
{
// make sure and dispose the data reference handle
// once we are done with it
DisposeHandle(dataRef);
}
myDataRef = createPointerDataRefWithExtensions(
data, /* pointer to data */
dataSize, /* size of data */
fileName, /* file name */
0, /* file type */
nil); /* mime type */
if (myDataRef)
{
OSErr err = noErr;
short id = 0;
Movie newMovie = NULL;
err = NewMovieFromDataRef(
&newMovie,
newMovieActive,
&id,
myDataRef,
PointerDataHandlerSubType);///////////////////////////////////////Here
it always return -2048
if (err == noErr)
{
// ... play/manipulate your movie here
_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden