Re: Reading MP3 data into a NSDocument using QTKit, -readFromData:, and QTDataReference
Re: Reading MP3 data into a NSDocument using QTKit, -readFromData:, and QTDataReference
- Subject: Re: Reading MP3 data into a NSDocument using QTKit, -readFromData:, and QTDataReference
- From: Michael Ash <email@hidden>
- Date: Mon, 9 Feb 2009 12:39:56 -0500
On Mon, Feb 9, 2009 at 10:56 AM, elliott cable <email@hidden> wrote:
> I'm sort of new to Cocoa, and C - as a learning project, I'm trying to
> write a very simple music/MP3 player.
>
> Currently, I'm stuck on getting MP3 data into the application and,
> well, playing it audibly. I've got a simple "Cocoa Document-based
> Application" template created, and have a simple UI that allows me to
> 'play' files: <http://github.com/elliottcable/farrier/blob/bbb0b3f582cf072618b684cac8f3c8eb2caacbde/MyDocument.m#L38-45>
>
> After a few days beating my head against that snippet, and trying to
> figure out why it failed to actually play any file that wasn't a
> simple .mov file, I found this old thread on this list:
> <http://lists.apple.com/archives/QuickTime-Users/2008/Nov/msg00026.html>
>
> I was excited, because it seemed to be the same problem as mine -
> playing anything that isn't .mov using QTKit. Unfortunately, after
> changing my code, I still have the same problem.
>
> Here's my latest attempt at the source of that method:
> <http://gist.github.com/60817#LID2> Unfortunately, that only prints
> the following to the log, and shows me this:
> <http://tr.im/ffgg?grabup>
>
> 2009-02-09 06:48:58.332 Farrier[3370:10b] MyDocument -readFromData:
> ofType:public.mp3 error:Error Domain=NSOSStatusErrorDomain Code=-1856
> "Operation could not be completed. (OSStatus error -1856.)" (handler
> not found )]
>
> Does anybody have any experience with opening and playing MP3 files in
> Cocoa with QTKit? (Or, for that matter, anything — I'm struggling at
> this point!)
I'm not sure, but I would bet that QTDataReference is not UTI-aware.
Try passing it a type like @"mp3" instead of @"public.mp3".
Better yet, in your NSDocument subclass, override
-readFromURL:ofType:error: instead of -readFromData:ofType:error:.
Then you can just hand the URL straight to QTKit and let it worry
about figuring out the type. This will also let QTKit lazily read the
data off disk instead of reading it all up front, a costly process for
large files.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden