how to use single instance of AVAudioPlayer for playing multiple songs?

I want to play multiple songs with single object of AVAudioplayer, I put songs in table row , when user tap on row player view is open but when user go back in other row in table player play both songs simanteniosly . what I Can do to fix this?


I assume that you have created the object in the h file, and have property declared and synthesized it. Also you might be playing the file from didSelectRowAtIndexPath: method. In that method you might have the following section of code.

AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: nil];
self.appSoundPlayer = newPlayer;
[newPlayer release];
[appSoundPlayer prepareToPlay];
[appSoundPlayer setVolume: 1.0];
[appSoundPlayer setDelegate: self];
[appSoundPlayer play];

Before [appSoundPlayer prepareToPlay]; add [appsoundPlayer stop]; just to ensure that the audioplayer is in stop state before starting the playing session.

If you are following a different method, just post the relevant part of the code here,

An AVAudioPlayer is meant to play a single audio clip. If you want to play a different clip, stop the current player, make a new one with the new audio data, and play it.

If two songs are overlapping then you're probably accidentally making two AVAudioPlayer instances and failing to stop the first one.

Need Your Help

Parse array of values - jQuery


Am calling a webservice from my jQuery to fetch both Staff and Student details. In my web service I have values for Staff as well as Students, and am returning these as array of strings. While retu...

resizing the second child view controllers view in iPad

ios objective-c ipad cordova uiviewcontroller

I am doing a PhoneGap iPad application. In this I had added a HybridPage (which contains webView) as a child view controller and then after that screen I am adding a New Controller (also removed the