Best way to play music

Discussion in 'Mac Programming' started by ranguvar, Jun 23, 2010.

  1. ranguvar macrumors 6502

    Joined:
    Sep 18, 2009
    #1
    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...
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. ranguvar thread starter macrumors 6502

    Joined:
    Sep 18, 2009
    #3
    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%.
     

Share This Page