标签:
IOS加载音频文件
需要导入#import <AVFoundation/AVFoundation.h>
1 NSString *path = [[NSBundle mainBundle] pathForResource:@"胭脂泪" ofType:@"mp3"]; //把音频文件转换成url格式 2 3 NSURL *urlStr = [NSURL fileURLWithPath:path]; 4 AVAudioPlayer * audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlStr error:nil]; 5 audioPlayer.volume = 1; //音量0.0~1.0之间 6 audioPlayer.numberOfLoops = -1; //循环次数 —1为无限循环播放 7 8 [audioPlayer play]; //音乐播放 9 10 audioPlayer.currentTime = 15.0; 11 12 13 14 NSUInteger channels = audioPlayer.numberOfChannels; //声道数(只读) 15 NSTimeInterval duration = audioPlayer.duration; //采样持续时间 16 audioPlayer.meteringEnabled = YES; //开启仪表技术功能 17 [audioPlayer updateMeters]; //更新仪表读数 18 19 [audioPlayer prepareToPlay]; //分配播放所需的资源并将其加入内部播放列队
停止播放
[audioPlayer stop];
标签:
原文地址:http://www.cnblogs.com/handonglengxueMing/p/5076536.html