【问题标题】:Watchkit presentAudioRecordingControllerWithOutputURL completion block issueWatchkit presentAudioRecordingControllerWithOutputURL 完成块问题
【发布时间】:2015-06-10 17:00:43
【问题描述】:

我只是试图满足以下函数的参数以调出录音机。我相信问题出在完成块上。调试中给出的错误是:

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");
                                            }
                                        }];

【问题讨论】:

    标签: objective-c recording


    【解决方案1】:

    我猜你的文件 URL recording 是错误的。您无法录制到“主包”中。所以无法创建 NSURL 对象并发生非 NULL 错误。

    例如,您可以按如下方式记录到 documents 目录中:

    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);
                                            }];
    

    【讨论】:

    • 谢谢,将录制文件的位置更改为有效的文件!
    猜你喜欢
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 2015-04-01
    相关资源
    最近更新 更多