UI高级第三课  音频视频——iOS学习连载31

1. URLWithString: 构建网络路径
2. fileURLWithPath: 构建本地路径
3. 由于当前 audioPlayer 没有被当前的控制器所持有,所以,为避免提前释放,需要将 audioPlayer 设置为实例变量
    AVAudioPlayer * audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error:&error];
4. 准备播放,分配播放所需要的资源,并将资源添加到播放队列中
    [audioPlayer prepareToPlay];
5. 使用 audioPlayer 进行停止功能,应该先暂停,再停止
6. 播放系统声音
(1)拿到系统声音文件地址
   
NSString *filePath = [[ NSBundle mainBundle ] pathForResource : @"44th Street Medium" ofType : @"caf" ];
(2) 构建 URL
   
NSURL *url = [ NSURL fileURLWithPath :filePath];
(3) SystemSoundID soundID;
(4) 将声音文件注册成为系统声音
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID);
7. 播放系统声音(只能在真机上看到效果)
    AudioServicesPlaySystemSound(soundID);
8.真机震动 (只能在真机上看到效果)
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值