views:

157

answers:

1

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?

A: 

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,

Nithin
You are assuming right but in didSelectRowAtIndexPath: method. i passes the name of song and this name is assign as url to player in its next view.
Abhijeet Barge
ok.. so you might have a play button there right??? or start playing right from the loading of view??
Nithin
yes. i have play button in next player view.
Abhijeet Barge
i m playing audio at tap event of button.
Abhijeet Barge
is it possible to do all with one common object of AVAudioPlayer ? if yes then how?
Abhijeet Barge
have you added the code for stopping the audioplayer? If you have, and still experiencing difficulty, post the code for that button event. Also in my code, appSoundPlayer is the synthesized instance of AVAudioPlayer.
Nithin
this is i did in didSelectRowAtIndexpath - PlayerViewController *playerView = [[PlayerViewController alloc] initWithNibName:@"PlayerViewController" bundle:nil]; NSUInteger row = [indexPath row]; playerView.FileName = [self.list objectAtIndex:row]; [self.navigationController pushViewController:self.playerView animated:YES];
Abhijeet Barge
I've posted my entire Action method @ http://stackoverflow.com/questions/2025461/avaudioplayer-not-releasing-memory/2025538#2025538
Nithin
and i assign it in playerview to player as like - NSString *path = [[NSBundle mainBundle] pathForResource:self.FileName ofType:nil]; NSURL *url = [NSURL fileURLWithPath:path];self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
Abhijeet Barge
Nithin
I need functionality like singleton class of player.
Abhijeet Barge
i did same as u comment
Abhijeet Barge
have you followed the code in the link that i posted earlier?? that was working fine for me,
Nithin
thanks dude for giving me ur time, but this code is not working for me.
Abhijeet Barge