官方文档
重点提示:
1、格式
- Linear PCM
- MA4 (IMA/ADPCM)
- µLaw
- aLaw
2、文件必须写在app bundle 或者沙盒Library/Sounds文件夹中
Place custom sound files in your app bundle or in the Library/Sounds folder of your app’s container directory. Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
3、读取文件直接写名字@"name",不用写
[NSBundle mainBundle] pathForResource:<#(nullable NSString *)#> ofType:<#(nullable NSString *)#>
或者沙盒路径。
附带将自己plist文件存入沙盒中代码
/* 写音频文件 */
- (void)writeMusicData {
NSString *bundlePath = [PPSDKbundle pathForResource:@"voip_call" ofType:@"caf"];
NSString *libPath = [NSHomeDirectory() stringByAppendingString:@"/Library/Sounds/"];
NSFileManager *manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:libPath]) {
NSError *error;
[manager createDirectoryAtPath:libPath withIntermediateDirectories:YES attributes:nil error:&error];
}
NSData *data = [NSData dataWithContentsOfFile:bundlePath];
BOOL flag = [data writeToFile:[libPath stringByAppendingString:@"voip_call.caf"] atomically:YES];
if (flag) {
NSLog(@"文件写成功");
}else{
NSLog(@"文件写失败");
}
}
网友评论