Here is my code on button click
- (void)playButton:(id)sender
{
NSLog(@"Play Button Clicked!!!...");
audioPlayer = [self setUpAudioPlayer:[songs objectAtIndex:i]];
}
-(AVAudioPlayer *)setUpAudioPlayer:(NSString *)filename
{
NSLog(@"File name : %@",filename);
NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"caf"];
NSLog(@"File path = %@",path);
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
//audioPlayer.volume = 0.5;
[audioPlayer prepareToPlay];
[audioPlayer play];
NSLog(@"Song is playing....");
return [audioPlayer autorelease];
}
here songs is NSMutableArray which contains file name… All things go correct with NSLog… But no sound is coming and no error comes.. What is wrong with the code..???
Your audio player is probably getting released as soon as it starts playing. Try to retain it after
setUpAudioPlayeris called.