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

ranguvar

macrumors 6502
Original poster
Sep 18, 2009
318
2
Hi,

I'm creating an iTunes replacement. The most essential part of the app is obviously playing music.

I looked at the CoreAudio (which seems to be more about creating music than just playing it) and QuickTime frameworks. Otherwise, accessing base APIs for each format (e.g. libmp3lame for mp3 support) would probably work, but be very work-intensive. I'm aiming for all formats supported by iTunes, extra formats would be a plus, but aren't required as of now.

What's the best way of playing music in a Mac OS X application?


EDIT: Found NSSound, which is extremely simple to use. Just playing the music with NSSound, no app loaded, needs 2% CPU. Fully-loaded QuickTime uses 2.9%, iTunes needs 2.5%. Wondering if they use NSSound...
 
Core Audio is the base API, QTKit and NSSound are just wrappers, QTKit obviously handling video as well.

Since iTunes is a Carbon app and mostly C-based, it's probably using the old QuickTime framework (which shouldn't be used anymore as it's not 64-bit).

If you're needing to do advanced audio analysis, you'll need to use Core Audio directly. Otherwise, QTMovie will probably do what you want.

Have your users install Perian and you'll be able to support a lot more formats via QTKit.
 
Core Audio is the base API, QTKit and NSSound are just wrappers, QTKit obviously handling video as well.

Since iTunes is a Carbon app and mostly C-based, it's probably using the old QuickTime framework (which shouldn't be used anymore as it's not 64-bit).

If you're needing to do advanced audio analysis, you'll need to use Core Audio directly. Otherwise, QTMovie will probably do what you want.

Have your users install Perian and you'll be able to support a lot more formats via QTKit.

OK, thanks. I'm using this code:

Code:
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
								fileName, QTMovieFileNameAttribute,
								[NSNumber numberWithBool:YES], QTMovieOpenForPlaybackAttribute,
								nil];
	
QTMovie *movie = [[QTMovie alloc] initWithAttributes:attributes error:NULL];
[movie autoplay];

CPU usage is about 2.0%.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.