tags:

views:

137

answers:

1

I've created a list of music file names in an array which is used to populate an uitableview. I want to make the audio player take this array or table as the playlist and play them continuously one by one, with all the features like play, pause, next, previous, forward, backward and stop. What is the best way to implement this. All the music files in the resource folder itself so that i can initiate each one as

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"mp3"];


NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
    self.soundFileURL = newURL;
    [newURL release];


    [[AVAudioSession sharedInstance] setDelegate: self];

    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];


AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: nil];
    self.appSoundPlayer = newPlayer;
    [newPlayer release];


    [appSoundPlayer prepareToPlay];
    [appSoundPlayer setVolume: 1.0];
    [appSoundPlayer setDelegate: self];
+1  A: 

Could this be as simple as implementing the AVAudioPlayerDelegate?

appSoundPlayer.delegate=self;

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
    if (successfully) 
    {
        // play next track
    }
}

Obviously you'd need to keep track of which track is currently playing in order to work out the next track to play, but that shouldn't be a problem. You'd also have to implement your own controls and logic for track skip etc, but again this is easily done.

cidered