1、导入头文件:
#import <AVFoundation/AVFoundation.h>
2、音乐播放能用到的几个简单的属性
@property (nonatomic,strong) UIProgressView *musicProgress;
@property (nonatomic,strong) AVAudioPlayer *player;
@property (nonatomic,strong) NSTimer *timer;
3、加载一些基本控件
-(AVAudioPlayer *)player {
if (!_player) {
//获取音频文件
NSString *music = [[NSBundle mainBundle] pathForResource:@"001" ofType:@"mp3"];
NSURL *musicUrl = [NSURL fileURLWithPath:music];
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicUrl error:nil];
//循环次数:1
//numberOfLoops = -1 是无限循环
_player.numberOfLoops = 1;
[_player prepareToPlay];
}
return _player;
}
//创建UI控件
-(void)creatrUI {
//创建button
NSArray *array = [NSArray arrayWithObjects:@"开始