My app uses Audio Unit to play mp3 files in IOS, but when the screen off, the sound stopped

StackOverflow https://stackoverflow.com/questions/18407209

  •  26-06-2022
  •  | 
  •  

Вопрос

My app uses AudioUnit to play mp3 files, totally used RemoteIO, NewTimePitch, AUConverter and MultiChannelMixer 4 AudioUnits.

My app could play when the screen is locked, but it can NOT play while the screen is off!

Even more Strangely, this issue only happens in Iphone4S(v6.1.3), but works fine in Iphone5(v6.1.4)!

here is my audio-unit setting code:

// connect audio unit: converter -> timepitch -> output
OSExcute( AUGraphConnectNodeInput(processingGraph, converterNode, 0, timepitchNode, 0) );
OSExcute( AUGraphConnectNodeInput(processingGraph, timepitchNode, 0, mixerNode, 0) );
OSExcute( AUGraphConnectNodeInput(processingGraph, mixerNode, 0, eqNode, 0) );
OSExcute( AUGraphConnectNodeInput(processingGraph, eqNode, 0, outputNode, 0) );

// try to fix no sound issue, but does not work
UInt32 maximumFramesPerSlice = 4096;    
OSExcute( AudioUnitSetProperty(mixerUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &maximumFramesPerSlice, sizeof (maximumFramesPerSlice)));
Это было полезно?

Решение

I have fixed this issue. The solution is: Set kAudioUnitProperty_MaximumFramesPerSlice to 4096 for EVERY audiounit except RemoteIO unit.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top