Search code examples
iosobjective-caudiovolumeplayback

AVAudioPlayer sound volume is very low


When playing a sound with AVAudioPlayer the volume is very low, you have to hold the phone close to the ears to hear anything, adjusting the volume with the volume buttons doesn't have much of an effect on it.

Do you know how I can fix this?


Solution

  • I made it work, I set kAudioSessionProperty_OverrideCategoryDefaultToSpeaker to true and it now works okay.

     UInt32 doChangeDefaultRoute = 1;
        AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(doChangeDefaultRoute), &doChangeDefaultRoute);
    

    Swift 2.0 syntax:

    audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: [.DefaultToSpeaker])
    

    you have to place it in a do block