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.
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")
}