Zaid Pathan Zaid Pathan - 4 months ago 72
iOS Question

AVAudioPlayer playing Sound with very low volume in iPhone 6 and 6+

I am playing a sound using


The sound volume in iPods (iOS7 & iOS8 both) is good.

But when I play same sound in iPhones the sound is playing with very low volume.

Here is my code:

var audioPlayer: AVAudioPlayer?
var soundURL:NSURL? = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sound", ofType: "mp3")!)

audioPlayer = AVAudioPlayer(contentsOfURL: soundURL, error: nil)
audioPlayer?.volume = 1

I've already included AudioToolbox.framework library in my project.

How can I improve sound in iPhone6 and 6+ ?


Recently i noticed that automatically the sound was increased for couple of seconds,but don't know what's wrong happening.?


I think if you set the volume of AVAudioPlayer to 1, then the problem is on the system volume. You may use a different audio category when playing your sound and the volume is different in different category or different audio route(like native speaker, headset or bluetooth) The default category in your app will be ambient, but the Music app's is playback. You can try to adjust your volume when you are playing your sound rather than before it's played.

Most probable issue is with audio session . Try these below line of codes

        do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        try AVAudioSession.sharedInstance().setActive(true)
    }  catch {
        print("AV session error")