【代码笔记】iOS-播放从网络上下载的语音
来源:互联网 发布:解密软件免费下载 编辑:程序博客网 时间:2024/05/17 01:28
代码:
ViewController.m
#import "ViewController.h"//录音#import <AVFoundation/AVFoundation.h>@interface ViewController (){ //播放器 AVAudioPlayer *player;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}//点击任何处的时候,播放声音-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //https://wifamily.blob.core.chinacloudapi.cn/wom/2015090211559116.mp3 //播放的时候声音小 AVAudioSession *audioSession = [AVAudioSession sharedInstance]; NSError *err = nil; [audioSession setCategory :AVAudioSessionCategoryPlayback error:&err]; NSString *voiceUrl=@"https://wifamily.blob.core.chinacloudapi.cn/wom/2015090211559116.mp3"; NSLog(@"---voiceUrl--%@",voiceUrl); NSURL *url = [[NSURL alloc]initWithString:voiceUrl]; NSData * audioData = [NSData dataWithContentsOfURL:url]; //将数据保存到本地指定位置 NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filePath = [NSString stringWithFormat:@"%@/%@.mp3", docDirPath , @"temp"]; [audioData writeToFile:filePath atomically:YES]; //播放本地音乐 NSError *playerError; NSURL *fileURL = [NSURL fileURLWithPath:filePath]; player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&playerError]; if (player == nil) { NSLog(@"--play--error---%@", [playerError description]); }else{ [player play]; } }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
阅读全文
0 0
- 【代码笔记】iOS-播放从网络上下载的语音
- 一段在网页上播放mp3语音的代码
- 从后台下载语音/视频并播放
- 从网络上下载图片的纠结
- iOS 播放网络音乐下载
- 【代码笔记】iOS-mp3的播放
- Vuforia在ios上全屏播放网络视频的方法
- IOS从网络下载图片
- 从网络下载音频资源的简便代码
- symbianoggplay从cvs上下载代码的设置
- 编译从GitHub上下载的代码中的caffe
- 播放网络上的视频
- 播放网络上的视频
- 播放网络上的视频
- 播放网络上的视频
- ijkplayer阅读学习笔记之从代码上看播放流程
- ijkplayer阅读学习笔记之从代码上看播放流程
- 用VBA代码下载网络上的文件
- 数据仓库建设
- Java的加密和解密艺术
- 界面的动画跳转
- 比较有用的网站
- iOS中OC加载HTML字符串
- 【代码笔记】iOS-播放从网络上下载的语音
- python web.py详解
- safari浏览器下 localStorage会报错的BUG
- C++ 虚函数表解析
- linux chmod的详细用法
- 『图论』LCA 最近公共祖先----Tarjan 算法
- ES6变量的解构赋值
- java switch 坑区
- GIT避免多次重复输入用户名密码