Looping an audio file

Hi. I have a .m4a file stored in my app that I'd like to do looping playback with. I'm looking at all of the audio frameworks and the only way I see right now is to use the Audio Toolbox APIs to load the file and then feed chunks of it into a queue via callbacks. This seems like a painfully low-level API for my needs.

Is there a way to just set up a playlist with the file that loops? The MediaPlayer framework has this, but it only seems to work with items that are in the user's media library. Not for regular audio files on disk.

Nevermind, I found AVAudioPlayer and it does exactly what I need. It wasn't listed in the documentation under the Audio section, so that's why I didn't see it.

Indeed but just for help in looking it up, here is an example :


    @property (strong) AVAudioPlayer* musicPlayer; //@import AVFoundation;

    self.musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"]] error:nil];
    self.musicPlayer.numberOfLoops = 500; //or -1 or 0 depending on needs
    self.musicPlayer.volume = 0.25f; 
    [self.musicPlayer prepareToPlay];
    [self.musicPlayer play];
Looping an audio file
 
 
Q