我一直有一些关于wav文件最近没玩的问题,我使用的是我两年前编写的代码(为ARC调整过),我很好奇,如果我这样做是最好的方式,因为iOS已经改变了从那以后呢?
@interface ViewController ()
@property (nonatomic, strong) AVAudioPlayer *buttonAudioPlayer;
@end
@implementation ViewController
@synthesize buttonAudioPlayer;
- (void)viewDidLoad {
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSError *error = nil;
NSURL *soundURL = [NSURL fileURLWithPath:[bundle pathForResource:@"buttonClick_002" ofType:@"wav"]];
[self setButtonAudioPlayer:[[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error]];
[buttonAudioPlayer prepareToPlay];
}
- (IBAction)buttonPressed {
NSLog(@"Button Pressed ...");
[[self buttonAudioPlayer] play];
}