EZAudio
EZAudio copied to clipboard
PlayFile Demo Crash When Screen Is Locked
In the demo PlayFile, when I set BackgroundMode on and allow audio play in background :
- Tap Home button, run in background successful.
- Tap Lock Screen button or wait to screen lock, the music stopped or crash.
![screen shot 2016-05-09 at 17 07 24](https://cloud.githubusercontent.com/assets/5388500/15108549/18b8f7e4-1609-11e6-87b7-fc1ca795c6ac.png)
environment : iPhone5s iOS 9.3.1
Run on simulator is totally fine. And there is no problem if I set AVAudioSession to PlayAndRecord.
I see this as well.
Placing a breakpoint in malloc_error_debug hasn't helped me at all, so I turned on Address Sanitizer. (edit schemes).
This causes an immediate break in
- (void)convertDataFromAudioBufferList:(AudioBufferList *)audioBufferList ...
at ..
[EZAudioUtilities checkResult:AudioConverterFillComplexBuffer(self.info->converterRef,
The issue is that for some reason when the lock screen is activated, the amount of frames goes from 1024 to 4096. And this triggers this offending line:
audioBufferList->mBuffers[i].mDataByteSize = frames * self.info->inputFormat.mBytesPerFrame;
Essentially, the bufferSize that was allocated was 4096, and the size is set to 16384 even though it is STILL only a buffer of 4096. This causes an overwrite of the buffer in AudioConverterFillComplexBuffer.
I'm not knowledgable enough to know if this is a bug in EZAudio, or a result of incorrect configuration of the properties that lead to the buffer initialization. It definitely seems EZAudio is wrong to blindly change the buffer size despite what it's ACTUAL capacity size it is.
I'm not sure what the proper fix for this is. You can work around it by multiplying 4 to the calculated buffer size in
EZAudioUtilities.m : audioBufferListWithNumberOfFrames
audioBufferList->mBuffers[i].mData = calloc(bufferSize * 4, 1);
Also see #303 which is unrelated to this, but related to lock screen.
That's work for me, thank you very much. And #303 is work for me too.
Please do not close this. My workaround is not a fix but an awful hack. We need to understand if this is a bug in EZAudio or a problem in setup of the properties that lead to buffer allocation, and this needs to be fixed.
Please reopen.
👌
This fix is causing crashes in my app, any idea what the actual fix is?
Have you ever take a look at #303, It works for me.