首页 > 移动平台 > 详细

IOS 多媒体加载 加载音频 AVAudioPlayer

时间:2015-12-25 18:58:43      阅读:291      评论:0      收藏:0      [点我收藏+]

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];

IOS 多媒体加载 加载音频 AVAudioPlayer

原文:http://www.cnblogs.com/handonglengxueMing/p/5076536.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!