【问题标题】:Apple Watch recording audio interface crashing after starting to recordApple Watch录音界面开始录音后崩溃
【发布时间】:2015-11-12 02:42:03
【问题描述】:

我正在尝试使用 Apple Watch 录制音频,使用 presentAudioRecorderControllerWithOutputURL 方法。

我正在使用 Xcode 7.0 beta 5、iOS9 beta、WatchOS 2 beta 和 Swift2。

它在模拟器上运行良好。但是,一旦在实际设备上,调用该方法时就会崩溃。

这是我当前的代码:

@IBAction func onClickSpeech() {
    let filePaths = NSSearchPathForDirectoriesInDomains(
        NSSearchPathDirectory.DocumentDirectory,
        NSSearchPathDomainMask.UserDomainMask,
        true)
    let documentDir = filePaths.first!
    let recSoundURL = documentDir + "/record.m4a"
    let nsUrl = NSURL.fileURLWithPath(recSoundURL)

    let audioOptions = [
        WKAudioRecorderControllerOptionsActionTitleKey  : "Recording title",
        WKAudioRecorderControllerOptionsAlwaysShowActionTitleKey : false,
        WKAudioRecorderControllerOptionsAutorecordKey: true,
        WKAudioRecorderControllerOptionsMaximumDurationKey: NSTimeInterval.infinity
    ]

    presentAudioRecorderControllerWithOutputURL(
        nsUrl,
        preset: WKAudioRecorderPreset.NarrowBandSpeech,
        options: audioOptions as [NSObject : AnyObject]) { (didSave, error) -> Void in
            print("didSave:\(didSave), error:\(error)")
    }
}

recSoundURL 是有效路径。

我在设备日志中遇到的错误:

Aug 18 16:42:12 Sennetts-AppleWatch mediaserverd[283] <Error>: 16:42:12.532 EXCEPTION: [0x1f1ac000] >va> 565: kAudioHardwareUnknownPropertyError: "AudioObjectHasProperty([goin/glob/0]) returned false."
Aug 18 16:42:12 Sennetts-AppleWatch mediaserverd[283] <Error>: 16:42:12.555 ERROR:    [0x1f1ac000] >va> 240: CAException caught by ExceptionBarrier: 2003332927.

任何想法都将不胜感激,因为我无法弄清楚这一点。谢谢。

【问题讨论】:

  • 可能是 Apple 的问题或错误。正如我们在日志中看到的,AudioObjectHasProperty([goin/glob/0]) 返回 false。他们可能会在 watchOS 2 公开发布后修复此问题。您应该使用 bugreport.apple.com 将错误提交给 Apple。
  • 是的,我已经完成了。我希望也许能在这里找到一些运气。现在我们就等着吧。
  • 我想知道是不是因为您需要将音频文件写入其他地方。在 Apple 提供的示例代码中,他们将其写入 NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("some identifier") link

标签: swift apple-watch watchos-2


【解决方案1】:

请看下面的代码(使用app group's共享文件夹)

    @IBAction func recordAudio() {

    let fileName = "audioFile.wav"

    let fileManager = NSFileManager.defaultManager()
    let container = fileManager.containerURLForSecurityApplicationGroupIdentifier(Constants.kAppGroupId)
    self.saveUrl = container?.URLByAppendingPathComponent(fileName)


    let duration = NSTimeInterval(120)
    let recordOptions = [WKAudioRecorderControllerOptionsMaximumDurationKey : duration]
    presentAudioRecorderControllerWithOutputURL(self.saveUrl!,
        preset: .WideBandSpeech,
        options: recordOptions,
        completion: { saved, error in

            if let err = error {
                print(err.description)
            }
            if saved {
                // Write code to execute when audio file gets saved.

            }
    })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2015-11-06
    相关资源
    最近更新 更多