I am playing a sound using AVAudioPlayer
.
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?.prepareToPlay()
audioPlayer?.volume = 1
audioPlayer?.play()
I've already included AudioToolbox.framework library in my project.
How can I improve sound in iPhone6 and 6+ ?
EDIT
Recently i noticed that automatically the sound was increased for couple of seconds,but don't know what's wrong happening.?
By and large, low sound coming from your iPhone speaker is the result of faulty app settings. Make sure mono audio and equalizer settings are turned off, and remove any apps that may override other sound settings. Otherwise, it's possible your phone's speaker may be either dirty, damaged, or both.
The volume is low because the sound is coming via the top speaker in iPhone(used for calling).
You have to override the AVAudioSession out put port to the main speaker.(bottom speaker)
This is the code that Route audio output to speaker
AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, error: &error)
Swift 3.0:
do {
try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.speaker)
} catch _ {
}
Solution for Swift 4
try? session.setCategory(.playAndRecord, mode: .default, policy: .default, options: .defaultToSpeaker)
P.S. For full class you can check my gist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With