AVAudioPlayer 在调试模式下抛出断点

每次我加载这个应用程序,它都会停止,就好像我在这一行上设置了一个断点:

self.audioPlayer =
[[[AVAudioPlayer alloc] initWithData:[dataPersister loadData:self.fileName]
error:&outError] autorelease];

上面没有断点,这条线附近也没有。只有在调试模式下运行应用程序时才会出现这种情况,而且在断点之后没有崩溃。当我点击“继续程序执行”时,应用程序工作正常。

这是用 initWithData调用的 loadData 方法:

-(NSData*)loadData:(NSString*)fileName
{
NSString *dataPath = [self.path stringByAppendingPathComponent:fileName];
dataPath = [dataPath stringByStandardizingPath];
NSData *data = [[[NSData alloc] initWithContentsOfFile:dataPath]autorelease ];
return data;
}

LoadData 函数似乎工作正常。请求的 mp3文件在断点之后加载并播放,没有任何问题。

你知道我哪里做错了吗?

编辑: 当它停在断点时,我回溯了一下,输出如下:

(lldb) bt
* thread #1: tid = 0x1c03, 0x30df1724 libc++abi.dylib`__cxa_throw, stop reason = breakpoint 1.2
frame #0: 0x30df1724 libc++abi.dylib`__cxa_throw
frame #1: 0x36403a24 AudioToolbox`ID3ParserHandle::ID3ParserHandle(void*, long (*)(void*, unsigned long, unsigned long, unsigned long, void**, unsigned long*)) + 452
frame #2: 0x36403b0e AudioToolbox`ID3ParserOpen + 142
frame #3: 0x3635bd16 AudioToolbox`MPEGAudioFile::ParseID3Tags() + 58
frame #4: 0x3635b9aa AudioToolbox`MPEGAudioFile::ParseAudioFile() + 26
frame #5: 0x3631723e AudioToolbox`AudioFileObject::DoOpenWithCallbacks(void*, long (*)(void*, long long, unsigned long, void*, unsigned long*), long (*)(void*, long long, unsigned long, void const*, unsigned long*), long long (*)(void*), long (*)(void*, long long)) + 166
frame #6: 0x36316480 AudioToolbox`AudioFileOpenWithCallbacks + 612
frame #7: 0x31f4c1ec AVFoundation`-[AVAudioPlayer initWithData:error:] + 120

“ Solutions”: 结果是,如果我对所有异常禁用异常断点,并且只对 Objective-C 异常使用断点,那么问题就会消失。但这并不能解决 AVAudioPlayer 的分配引发 C + + 异常的问题。

12016 次浏览

AVAudioPlayer and AVAudioRecorder both will throw exceptions, several of them. These are handled internally by the players but if you have a breakpoint for "All Breakpoints" (i.e. Exception: All, Break: On Throw) you will catch these exceptions. If you continue execution on these, the app will continue to run normally and not crash at all.

The only solution I've come up with so far is to click on the breakpoint bar in the Breakpoint Navigator, disabling this particular breakpoint, and running with it disabled.

When/if the app ever crashes with a thrown exception, I cmd-6, enable that breakpoint, and rerun and do whatever I did when it crashed.

Edit: setting to "Objective-C exceptions" is obviously how to do it. See above answer!

Add your exception breakpoint and edit the exception type from "All" to "Objective-C exceptions"

Some classes in AudioToolbox throw regular C++ exceptions. You can filter them off this way.

The backtrace helped a lot, thanks!. We'd started running into the same issue recently. It turns out the mp3 files it was throwing on did not have a valid ID3 tag and running them through an app such as Tagr fixed them right up!

Try setting the AVAudioPlayer as a class Variable!

Here's a screenshot showing how I fixed this error. I'm not sure if this is the same way that the answers above are talking about, but I assume its similar.

  1. Go to the Breakpoint navigator in Xcode.
  2. Control-click on the 'All Exceptions' line.
  3. Select the 'Edit Breakpoint...' option.
  4. Change the Exception from All to Objective-C.

enter image description here

In Xcode 9.2 you can disable specific exceptions after you've seen them. Open breakpoints menu and click to disable (faded arrow)

enter image description here