iOS将网络音频文件写入本地的方法
2016-01-07 10:38
501 查看
//创建保存文件路径
fileName:文件名
type:文件类型
- (NSString*)getPathByFileName:(NSString *)fileName ofType:(NSString*)type{
//创建dcument文件路径
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
//完成创建文件路径
NSString* fileDirectory = [[[directory stringByAppendingPathComponent:fileName]
stringByAppendingPathExtension:type]
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return fileDirectory;
}
//文件的路径
NSString *self.amrPath;
self.amrPath = [self getPathByFileName:model.CreateTime ofType:@"amr"];
//soundUrl为音频文件URL
NSData *data = [NSDat dataWithContentsOfURL[[NSUR alloc]initWithString:SoundUrl]];
//写入文件中
[data writeToFile:self.amrPath atomically:YES];
fileName:文件名
type:文件类型
- (NSString*)getPathByFileName:(NSString *)fileName ofType:(NSString*)type{
//创建dcument文件路径
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
//完成创建文件路径
NSString* fileDirectory = [[[directory stringByAppendingPathComponent:fileName]
stringByAppendingPathExtension:type]
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return fileDirectory;
}
//文件的路径
NSString *self.amrPath;
self.amrPath = [self getPathByFileName:model.CreateTime ofType:@"amr"];
//soundUrl为音频文件URL
NSData *data = [NSDat dataWithContentsOfURL[[NSUR alloc]initWithString:SoundUrl]];
//写入文件中
[data writeToFile:self.amrPath atomically:YES];
相关文章推荐
- 关于使用QTcpSocket的一些总结
- 解决github unable to access 'https://github.com/...: Failed to connect to github.com port 443
- 在CentOS7中开启httpd的mod_ssl 模块及配置
- java模拟http get和post 提交 httpclient
- TCP接受和发送程序以及长连接的处理方法
- 详解HttpURLConnection
- URL,URLConnection,HttPURLConnection的使用
- Android 封装http请求的工具类
- APP 检测网络的状态 是wifi 还是蜂窝连接
- 深入了解HTTP和Socket在实时性Web上的实践
- libevent的http服务与libjson结合
- Http 协议
- Android:3G网络是否可用
- 2016【太原网络营销师】郭文军教你如何学网络营销
- 消除SDK更新时的“https://dl-ssl.google.com refused”异常
- Mac用CornerStone配置SVN,HTTP及svn简单使用说明
- asp.net中http提交数据所遇到的那些坑
- [原]unity3d之http多线程异步资源下载
- SDH,OTN,IP,MPLS,ATM网络介绍
- Android之使用Http协议实现文件上传示例(上传MP3文件)