0

我正在尝试将录制的音频文件保存在文档文件夹中。我试图用它CoreData来保存录制的音频,但我无法弄清楚。集成它的最佳方法是什么?我的代码如下: -

    if(_radio.isRecording) {
        [_recordbutton setImage:[UIImage imageNamed:@"record_off.png"] forState:UIControlStateNormal];
        [_radio stopRecording];
    }  else {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsPath = [paths objectAtIndex:0];
        NSString *recordname = [NSString stringWithFormat:@"%@%d.%@", [_detailItem objectForKey:@"name"], _recordingCounter++, [_radio fileExtensionHint]];
        NSString *path = [documentsPath stringByAppendingPathComponent:recordname];
        [_recordbutton setImage:[UIImage imageNamed:@"record_on.png"] forState:UIControlStateNormal];
        [_radio startRecordingWithDestination:path];

    }
}

- (void)radio:(MeroRadio *)radio didStopRecordingWithDestination:(NSString *)path {

    NSLog(@"Did stop recording with destination: %@", path);
    [_recordbutton setImage:[UIImage imageNamed:@"record_off.png"] forState:UIControlStateNormal];
    NSURL *url = [NSURL fileURLWithPath:path];
    [_recordings saveobject:[url lastpathcomponent];

}

_recordings是一个NSMutableArray。那么保存它的最佳方法是什么?

4

1 回答 1

0
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

NSArray *documentsFolders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[documentsFolders objectAtIndex:0] stringByAppendingPathComponent:@"Recording.aiff"];

[library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:path] completionBlock:^(NSURL *assetURL, NSError *error){

    /*notify of completion*/

    NSLog(@"AssetURL: %@",assetURL);
    NSLog(@"Error: %@",error);

    if (!error) {
        //video saved

        [[self appDelegate] showAlertWithTitle:@"Audio Saved" message:@""];

    }
    else{

        [[self appDelegate] showAlertWithTitle:@"Error" message:error.domain];

    }

}];
于 2014-04-24T05:56:19.020 回答