Reputation: 1586
I have the following code for playing a click when a button is tapped.
private var clickSound: SystemSoundID!
clickSound = createSound("ButtonClick2", soundType: "wav")
AudioServicesPlaySystemSound(clickSound)
This sound plays at the same level, regardless of the volume on the device and whether the device is muted.
This is really two questions.
Upvotes: 0
Views: 2190
Reputation: 979
You can get the System Volume
let volume = AVAudioSession.sharedInstance().outputVolume
print("Output volume: \(volume)"
the value of volume is from 0.0 to 1.0
Upvotes: 1
Reputation: 2098
The reason this doesn't respond to user sound level is you created a system sound. Instead, use AVAudioPlayer
.
do {
let player = try AVAudioPlayer(contentsOf: soundFileURL)
player.play()
} catch {
print("Error")
}
Upvotes: 2