Program Background Music

Discussion in 'iOS Programming' started by Soulstorm, Mar 23, 2009.

  1. Soulstorm macrumors 68000


    Feb 1, 2005
    I am building a simple program as proof of concept and I want to add background music to it. What is the best way to have a music being played in the background without much compromise in performance? What frameworks will I use? Will I need to write that code to the application's delegate?

    Does background music use many system resources from the iPhone OS?

    Note that I want the background music to be looped!

    Any recommendations are well appreciated.
  2. Buschmaster macrumors 65816


    Feb 12, 2006
  3. orchiss macrumors newbie

    Mar 19, 2009
    Check out the crash landing app - SoundEngine.cpp and .h

    There's no example of the background music, so here's a bit to get you started:

    NSBundle*	 bundle = [NSBundle mainBundle];
      SoundEngine_SetListenerPosition(0.0, 0.0, 1.0);
      SoundEngine_LoadBackgroundMusicTrack([[bundle  pathForResource:@"your_file_name" ofType:@"caf"] UTF8String],NO,YES);
    Keep in mind the format for this seems to be really picky. I'm using a .caf file. Make sure your encodings are in little endian order too.
    For converting wav to caf:
    afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf

    Hope that gives you a starting point.

  4. Soulstorm thread starter macrumors 68000


    Feb 1, 2005
    Thanks a lot for your answer! Yes, the iPhone is really picky about resources. It uses caf for sound and pvrtc for images. I wish I knew why, though!

Share This Page