开发者

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

I want to play multiple so开发者_开发技巧ngs 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜