iDevGames Forums
Playing MP3 from Cocoa - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Playing MP3 from Cocoa (/thread-7285.html)

Playing MP3 from Cocoa - BeyondCloister - Feb 21, 2003 01:00 PM

Can anyone point me in the direction of any sample code for playing an MP3 from Cocoa so I can add background music to my Chromacell game?


Playing MP3 from Cocoa - OneSadCookie - Feb 21, 2003 01:24 PM

Just use QuickTime with straight C. QTValuePak has an example that can play an MP3.

Playing MP3 from Cocoa - BeyondCloister - Feb 26, 2003 03:33 PM

Thanks for the suggestion.

How easy is it to integrate C code into the middle of Objective-C Cocoa code?

I was hoping to do everything in Objective-C Cocoa, but if it is not possible then I will have to follow this path.

Playing MP3 from Cocoa - Tycho - Feb 26, 2003 03:36 PM

Since Objective C is a superset of C, I wouldn't think it would be too hard. There's not really any "integration" involved.

Playing MP3 from Cocoa - Fenris - Feb 26, 2003 03:43 PM

Nope, just call the C functions as usual, as you would call any Obj-C method.

[myVar retain];
PlayMovieFromFile (your arguments go here);
[myVar release];

Playing MP3 from Cocoa - quillbit - Feb 26, 2003 05:00 PM

Just instantiate with [NSMovie initWithURL:byReference:] and pass [NSMovie QTMovie] to your QuickTime functions -- it's not quite toll-free bridged, but the access charge is very low. To wit:


// (use NSBundle to get your resource path here) ...

soundClip = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: pathStringHere]
byReference: NO];

StartMovie([soundClip QTMovie]);


Playing MP3 from Cocoa - Komick - Mar 20, 2003 07:21 PM

I found this yesterday. Hope it's helpful.