iOS学习笔记31-音频
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property(nonatomic,strong)AVAudioPlayer *player;
@end
@implementation ViewController
-(AVAudioPlayer *)player
{
if (!_player) {
NSURL *url = [[NSBundle mainBundle]URLForResource:@"爱火花.mp3" withExtension:nil];
_player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
[self.player prepareToPlay];
}
return _player;
}
- (IBAction)play {
[self.player play];
}
- (IBAction)pause:(id)sender {
[self.player pause];
}
- (IBAction)stop {
[self.player stop];
}