应用场景:多套声音,供用户动态选择
实现:
1、server端去修改
2、native端修改
具体来讲:声音文件可以放到app bundle里面,或者如果是从网上下载的话就放在你pp沙盒目录下的Library/Sounds。自定义声音必须少于30秒。如果大于30秒将会用默认的系统的提示音取代。
bundle与沙盒声音重名 播放沙盒中的
-(NSString *)libraryPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryPath = [paths lastObject];
// NSLog(@"%@", libraryPath);
return libraryPath;
}
- (void)setData {
NSString *path = [self libraryPath];
NSString *dataFilePath = [path stringByAppendingPathComponent:@"Sounds"];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = NO;
// fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
BOOL existed = [fileManager fileExistsAtPath:dataFilePath isDirectory:&isDir];
if ( !(isDir == YES && existed == YES) ) {
// 在 Document 目录下创建一个 head 目录
[fileManager createDirectoryAtPath:dataFilePath withIntermediateDirectories:YES attributes:nil error:nil];
NSString *mp3Path = [[NSBundle mainBundle] pathForResource:@"newOrder_1" ofType:@".mp3"];
NSString *copyPath = [dataFilePath stringByAppendingPathComponent:@"newOrder.mp3"];;
NSError *err;
[fileManager copyItemAtPath:mp3Path toPath:copyPath error:&err];
}
NSLog(@"+++++++++++++++++++%@",dataFilePath);
}
网友评论