Program Background Music

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

  1. Soulstorm macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #1
    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

    Buschmaster

    Joined:
    Feb 12, 2006
    Location:
    Minnesota
  3. orchiss macrumors newbie

    Joined:
    Mar 19, 2009
    #3
    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:

    Code:
     
    NSBundle*	 bundle = [NSBundle mainBundle];
      SoundEngine_Initialize(44100);
      SoundEngine_SetListenerPosition(0.0, 0.0, 1.0);
      SoundEngine_LoadBackgroundMusicTrack([[bundle  pathForResource:@"your_file_name" ofType:@"caf"] UTF8String],NO,YES);
      SoundEngine_StartBackgroundMusic();
    
    
    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.

    -M
     
  4. Soulstorm thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #4
    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