#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];
}
时间: 2024-10-25 14:52:56