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
2010-04-07 10:54:00
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
2010-04-07 11:04:44
ok.. so you might have a play button there right??? or start playing right from the loading of view??
Nithin
2010-04-07 11:15:46
yes. i have play button in next player view.
Abhijeet Barge
2010-04-07 11:18:03
i m playing audio at tap event of button.
Abhijeet Barge
2010-04-07 11:19:15
is it possible to do all with one common object of AVAudioPlayer ? if yes then how?
Abhijeet Barge
2010-04-07 11:22:09
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
2010-04-07 11:22:20
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
2010-04-07 11:27:25
I've posted my entire Action method @ http://stackoverflow.com/questions/2025461/avaudioplayer-not-releasing-memory/2025538#2025538
Nithin
2010-04-07 11:29:13
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
2010-04-07 11:29:23
Nithin
2010-04-07 11:34:10
I need functionality like singleton class of player.
Abhijeet Barge
2010-04-07 11:37:47
i did same as u comment
Abhijeet Barge
2010-04-07 11:39:32
have you followed the code in the link that i posted earlier?? that was working fine for me,
Nithin
2010-04-07 11:41:48
thanks dude for giving me ur time, but this code is not working for me.
Abhijeet Barge
2010-04-07 11:44:18