- 暂停和停止的效果木有区别!
#import "ViewController.h"#import@interface ViewController ()
//这个要用�强指针是因为 播放器要持续播放,记录之后,走出ViewDidload方法也会存在
@property(nonatomic,strong) AVAudioPlayer * player;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//准备URl
NSURL * URl= [[NSBundle mainBundle] URLForResource:@"童话.mp3" withExtension:nil];
//实例化播放器
AVAudioPlayer * player = [[AVAudioPlayer alloc]initWithContentsOfURL:URl error:nil];
//准备 不谢这个方法也是可以的,这个方法会开辟空间,如果不写自动调用,谢了效果更好;
[player prepareToPlay];
self.player = player;
}
- (IBAction)start:(UIButton *)sender {
[self.player play];
}
- (IBAction)pause:(UIButton *)sender {
[self.player pause];
}
- (IBAction)stop:(id)sender {
[self.player stop];
}
@end
网友评论