Watchkit presentAudioRecordingControllerWithOutputURL完成块问题

时间:2015-06-10 17:00:43

标签: objective-c recording

我只是试图满足以下功能的参数来调出录音机。我认为问题在于完成块。调试中给出的错误是:

  

presentAudioRecordingControllerWithOutputURL:preset:maximumDuration:actionTitle:completion:需要一个非NULL的URL和完成块

NSBundle* myBundle = [NSBundle mainBundle];
NSURL* recording = [myBundle URLForResource:@"recording" withExtension:@"mp4"];

[self presentAudioRecordingControllerWithOutputURL:recording
                                            preset:WKAudioRecordingPresetWideBandSpeech
                                   maximumDuration:5000
                                       actionTitle:@"Recording"
                                        completion:^(BOOL didSave, NSError *error) {
                                            if (error != nil)
                                            {
                                               NSLog(@"Error: %@",error);
                                            }
                                            else if(didSave == YES)
                                            {
                                                NSLog(@"Saved the recording");
                                            }
                                        }];

1 个答案:

答案 0 :(得分:2)

我猜您的文件网址recording是错误的。您无法录制到“主程序包”中。因此无法创建NSURL对象并发生非NULL错误。

例如,您可以按如下方式录制到文档目录中:

NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask,YES);
NSString *path = [[filePaths firstObject] stringByAppendingPathComponent:@"recording.mp4"];
NSURL *fileUrl = [NSURL fileURLWithPath:path];

[self presentAudioRecordingControllerWithOutputURL:fileUrl
                                            preset:WKAudioRecordingPresetWideBandSpeech
                                   maximumDuration:5000
                                       actionTitle:@"Recording"
                                        completion:^(BOOL didSave, NSError * __nullable error) {

                                            NSLog(@"didSave:%d, error:%@", didSave, error);
                                        }];