views:

70

answers:

3

Hello,

Is there an easy way to load, play and control an mp3 file from cocoa? Tried googling it, but, as all things apple, i get messy results and have no idea where to start. As i understand, there's and NSSound, but it has lots of limitations and then there's CoreAudio, but it's very difficult. So can someone point me in a right direction with this? Thanks.

A: 

I've written a framework in C++ that might help: http://github.com/sbooth/SFBAudioEngine

It supports multiple audio formats and has a fairly benign API and comes with a Cocoa sample.

If you're not interested in third-party frameworks, your bet would probably be to use an AudioQueue to take care of the playback. To do this, you'd probably use AudioFile to decode the MP3 and AudioQueue for the playback. Apple has an example at http://developer.apple.com/mac/library/samplecode/AudioQueueTools/Introduction/Intro.html

sbooth
A: 

Besides NSSound, you could consider QTMovieView. It sounds odd, but you can have a hidden QTMovieView in your window and use it to play an MP3.

JWWalker
I've also seen examples with QTKit without any views, but i'm not sure if this is a good way to do it, since i haven't found how to seek a file or maybe even add some effects later.
Marius
I'm not sure what you mean by "seek a file".
JWWalker
Well, in simpler terms, go to some specific position and continue playing from there.
Marius
Oh, OK... when using QTMovieView, you can use QTMovie methods such as `setCurrentTime:` on the associated QTMovie.
JWWalker
Thanks. Would it be possible to add some audio effects to QTMovie later? Like reverb, equalizer etc.? Or is it only possible for CoreAudio?
Marius
I can't swear that it can't be done, but I don't recall seeing anything about using audio effects on a QTMovie.
JWWalker
+1  A: 

Use NSSound.

You didn't specify what you mean by “lots of limitations”, so I don't know why this won't work for you. Note that it has a lot fewer limitations since Leopard; you can now play to any device, for example.

Peter Hosey