Loop background music?

Viewed 11429
  1. What's the best way of playing background music for my iOS game? And how do I do this?

  2. What's the best format of having that music file in for playback?

  3. Will this this song happily play through the entire game, no interruptions when changing view?

  4. How can I loop this music?

1 Answers

You can use the AVAudioPlayer:

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = -1; //infinite

[player play];

and you can jump through by setting the currentTime:

player.currentTime = 10; //jump to 10th second
Related