Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nishad

macrumors newbie
Original poster
Aug 2, 2007
11
0
Hi all,

I am facing problem to create QTMovie object with class method -movieWithData:error:, if movie format other than mov.

I wrote like this,

NSData *data = [[NSData alloc] initWithContentsOfFile: path];

//path store the path of file.

NSError *error;
QTMovie *movie = [QTMovie movieWithData: data error:&error];

if(error != nil)
NSLog("error %@", error);

[movieView setMovie:movie];


if the file is other than mov, say mp3 , this code giving error message as

NSError "the file is not a movie file" Domain=NSOSStatusErrorDomain Code=-2048 UserInfo={NSLocalizedDescription = "the file is not a movie file";


if i create qtmovie object with class method movieWithFile: i can create the object and play the file. but in app i want to initialize QTMovie object with NSData.

Can anybody give solution for this or what is the mistake i have done here.


with Thanks & regards,
Nish.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If movieWithFile:error: works, try writing the data to a temporary file and then loading it from there instead. Probably more efficient anyways.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
The QT methods are convenience wrappers and as such they hide a lot of complexity. Try doing something like this:

Code:
    if ([QTMovie canInitWithURL:url])
    {
        if ([type isEqualTo:kDocDataTypeName])
        {
            NSData *data = [NSData dataWithContentsOfURL:url];
            [self setMovie:[QTMovie movieWithData:data error:nil]];
            success = (mMovie != nil);
        }
        else
        {
            [self setMovie:((QTMovie *)[QTMovie movieWithURL:url error:nil])];
            success = (mMovie != nil);
    }

What I suspect is happening is that the raw data from the MP3 file is missing QT "atoms" or other meta data/hints that QuickTime users to figure out what to do with the data. Otherwise reading the same data from a discrete file would also not work, as QT can figure out that file with .mp3 or other meta data present means the raw data is in MP3 format.

Look around the API docs, they have a lot of info on this kind of thing and then there are all the sample code downloadable archives you can look at.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.