Fresh SpeakHere example app has error when recording audio in Simulator/Xcode

前端 未结 2 1304
长情又很酷
长情又很酷 2021-01-15 06:36

I can\'t record audio using the SpeakHere example app from apple. When I run the app in Simulator from within Xcode, it starts up normally, but when I press the record butto

2条回答
  •  误落风尘
    2021-01-15 07:02

    The problem occurs because in the method AQRecorder::StartRecord(CFStringRef inRecordFile), the function CFURLCreateWithString() fails and returns a pointer to nil. This is not detected and later on the code calls CFRelease() on this nil pointer, which causes the EXC_BREAKPOINT.

    The purpose of the method CFURLCreateWithString() basically is to take a url string as input and return a pointer to a CFURL object as output. The problem here is that the input is not a url string. Instead, it's simply a path on the local file system without file:/ or the like as prefix. For this reason, this method fails.

    The solution is to remove the not-working call to the method CFURLCreateWithString() and instead call a related method, namely CFURLCreateWithFileSystemPath(), which is prepared to take a local file system path and convert it to a CFURL:

    In the method AQRecorder::StartRecord(CFStringRef inRecordFile), replace or comment out the line

    url = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)recordFile, NULL);
    

    and insert

    url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)recordFile, kCFURLPOSIXPathStyle, false);
    

    at its place.

提交回复
热议问题