Create QTMOvie object for file other than mov

Discussion in 'Mac Programming' started by Nishad, Nov 4, 2008.

  1. Nishad macrumors newbie

    Joined:
    Aug 2, 2007
    #1
    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.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    If movieWithFile:error: works, try writing the data to a temporary file and then loading it from there instead. Probably more efficient anyways.
     
  3. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #3
    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.
     

Share This Page