Я написал эту исходную программу.Но я не могу вызвать audioPlayerDidFinishPlaying: метод.После воспроизведения звука, который вылетает из-за ошибки «exc_bad_access» через несколько секунд.
.h file
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface SecondViewController : UIViewController<
AVAudioPlayerDelegate>{
AVAudioPlayer *aPlayer;
}
@end
.m file
-(void)playSound{
NSString *soundName = @"red";
NSError *error = nil;
NSURL *soundUrl = [[NSBundle mainBundle] URLForResource:soundName withExtension:@"mp3"];
aPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:&error];
if (error != nil) {
NSLog(@"audio_player initialized error :(%@)",[error localizedDescription]);
[aPlayer release];
error=nil;
return;
}
NSLog(@"player Ok!");
aPlayer.delegate = self;
[aPlayer prepareToPlay];
aPlayer.volume=1.0f;
[aPlayer play];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
[player release];
}