EZAudio icon indicating copy to clipboard operation
EZAudio copied to clipboard

PlayFile Demo Crash When Screen Is Locked

Open saitjr opened this issue 8 years ago • 8 comments

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

environment : iPhone5s iOS 9.3.1

Run on simulator is totally fine. And there is no problem if I set AVAudioSession to PlayAndRecord.

saitjr avatar May 09 '16 09:05 saitjr

I see this as well.

dxclancy avatar May 31 '16 23:05 dxclancy

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.

dxclancy avatar Jun 01 '16 01:06 dxclancy

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.

dxclancy avatar Jun 01 '16 01:06 dxclancy

That's work for me, thank you very much. And #303 is work for me too.

saitjr avatar Jun 01 '16 08:06 saitjr

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.

dxclancy avatar Jun 01 '16 15:06 dxclancy

👌

saitjr avatar Jun 02 '16 01:06 saitjr

This fix is causing crashes in my app, any idea what the actual fix is?

matanvr avatar Jun 10 '16 07:06 matanvr

Have you ever take a look at #303, It works for me.

saitjr avatar Jun 11 '16 05:06 saitjr