音乐的播放

- 暂停和停止的效果木有区别!

#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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容