將音頻文件比如mp3、caf等音頻文件制作為鈴聲,但是庫(kù)樂(lè)隊(duì)app需要文件.band的格式才能打開(kāi)

ExtAudioConverter 講音頻轉(zhuǎn)換成.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(@"轉(zhuǎn)化成功");
? ? }
? ? NSString *bandDir = [tmpBandDir stringByAppendingString:@".band"];
? ? [fileManagermoveItemAtPath:tmpBandDirtoPath:bandDirerror:nil];
? ? returnbandDir;
}