IOS加载音频文件
需要导入#import <AVFoundation/AVFoundation.h>
NSString *path = [[NSBundle mainBundle] pathForResource:@"胭脂泪" ofType:@"mp3"]; //把音频文件转换成url格式
NSURL *urlStr = [NSURL fileURLWithPath:path];
AVAudioPlayer * audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlStr error:nil];
audioPlayer.volume = 1; //音量0.0~1.0之间
audioPlayer.numberOfLoops = -1; //循环次数 —1为无限循环播放
[audioPlayer play]; //音乐播放
audioPlayer.currentTime = 15.0;
NSUInteger channels = audioPlayer.numberOfChannels; //声道数(只读)
NSTimeInterval duration = audioPlayer.duration; //采样持续时间
audioPlayer.meteringEnabled = YES; //开启仪表技术功能
[audioPlayer updateMeters]; //更新仪表读数
[audioPlayer prepareToPlay]; //分配播放所需的资源并将其加入内部播放列队
停止播放
[audioPlayer stop];