I am using AVFoundation to play wav files. But i could not make it play. Also no errors or warnings showed up.
XCode is 4.2 and device is iOS 5.
- (IBAction) playSelectedAlarm:(id)sender {
UIButton *button = (UIButton *)sender;
int bTag = button.tag;
NSString *fileName = [NSString stringWithFormat:@"%d23333", bTag];
NSLog(@"%@", fileName);
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: path];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:NULL];
theAudio.volume = 1.0;
theAudio.delegate = self;
[theAudio prepareToPlay];
[theAudio play];
}
Here is the solution;
I set AVAudioPlayer in header file..
@property (nonatomic, retain) AVAudioPlayer *theAudio;
i guess ‘retain’ is solved my problem. Because after i sending “play”, it sends “release” to balance the alloc. When AVAudioPlayer is deallocated it stops playing audio.