将音频文件比如mp3、caf等音频文件制作为铃声,但是库乐队app需要文件.band的格式才能打开
ExtAudioConverter 讲音频转换成.aiff格式//生成新的BandFilePath
- (NSString*)generateBandFile:(NSString*)filePath{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fileName = [[filePath lastPathComponent] stringByDeletingPathExtension];
NSString* cachePath=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString*tmpBandDir = [cachePathstringByAppendingPathComponent:fileName];
if([fileManagerfileExistsAtPath:tmpBandDir]) {
[fileManagerremoveItemAtPath:tmpBandDirerror:nil];
}
NSString *bandFilePath = [[NSBundle mainBundle] pathForResource:
@"bandName"ofType:@"band"];
if([fileManagerfileExistsAtPath:bandFilePath]){
[fileManagercopyItemAtPath:bandFilePathtoPath:tmpBandDirerror:nil];
}
NSString *ringtonefile = [tmpBandDir stringByAppendingPathComponent:@"Media/ringtone.aiff"];
ExtAudioConverter* converter = [[ExtAudioConverter alloc] init];
converter.inputFile= filePath;
converter.outputFile= ringtonefile;
converter.outputFileType = kAudioFileAIFFType;
if([converterconvert]) {
NSLog(@"转化成功");
}
NSString *bandDir = [tmpBandDir stringByAppendingString:@".band"];
[fileManagermoveItemAtPath:tmpBandDirtoPath:bandDirerror:nil];
returnbandDir;
}