Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re Create a movie from a memory pointer



Edward Agabeg 写道:
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.

http://developer.apple.com/technotes/tn/tn1195.html

regards,
edward

Edward Agabeg
WWDR Engineer
QuickTime and Audio
Worldwide Developer Relations
Apple

http://www.apple.com/developer
http://www.apple.com/quicktime

-- This message was sent from a personal account --
-- All views are mine and not necessarily shared by my employer --
------------------------------------------------------------------------


Thank you for your reply.I am sorry,but I did see this LINK http://developer.apple.com/technotes/tn/tn1195.html <http://developer.apple.com/technotes/tn/tn1195.html>

_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.
//
//////////

OSStatus PtrDataRef_AddFileNameExtension(
ComponentInstance dataRefHandler, /* data ref. handler */
Str255 fileName) /* file name for extension */
{
OSStatus anErr = noErr;
unsigned char myChar = 0;
Handle fileNameHndl = NULL;

/* create a handle with our file name string */

/* if we were passed a null string, then we
need to add this null string (a single 0
byte) to the handle */

if (fileName == NULL)
anErr = PtrToHand(&myChar, &fileNameHndl, sizeof(myChar));
else
anErr = PtrToHand(fileName, &fileNameHndl, fileName[0] + 1);
if (anErr != noErr) goto bail;

/* 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;

myType = EndianU32_NtoB(fileType);

anErr = PtrToHand(&myType, &fileTypeHndl, sizeof(OSType));
if (anErr != noErr) goto bail;

/* 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;

if (mimeType == NULL)
return paramErr;

anErr = PtrToHand(mimeType, &mimeTypeHndl, mimeType[0] + 1);
if (anErr != noErr) goto bail;

/* 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. // //////////

Handle MyCreatePointerReferenceHandle(void *data, Size dataSize)
{
Handle dataRef = NULL;
PointerDataRefRecord ptrDataRefRec;
OSErr err;


ptrDataRefRec.data = data; ptrDataRefRec.dataLength = dataSize;

// create a data reference handle for our data
err = PtrToHand( &ptrDataRefRec, &dataRef, sizeof(PointerDataRefRecord));

return dataRef;
}



Handle createPointerDataRefWithExtensions(
void *data,
Size dataSize,
Str255 fileName,
OSType fileType,
StringPtr mimeTypeString
)
{
OSStatus err = noErr;
Handle dataRef = NULL;
ComponentInstance dataRefHandler = NULL;

// 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);
}

return NULL;
}

void createMovieFromMemory(void *data,
Size dataSize,
Str255 fileName)
{
Handle myDataRef = NULL;

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


// clean up when finished using movie

DisposeMovie(newMovie);
}

// more clean up
DisposeHandle(myDataRef);
}
}


main() is like this below:

InitializeQTML(0);
EnterMovies();
short id=0;

Str255 strFileName="test.mp3";

createMovieFromMemory(pData,iDataSize,strFileName);




_______________________________________________ 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

This email sent to email@hidden
References: 
 >Re Create a movie from a memory pointer (From: "Edward Agabeg" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.