Add possibility to disable sound effects

This commit is contained in:
Daniel Steckert 2020-06-25 17:47:25 +02:00
parent 9b1ff1d4ae
commit 58f6032e06

View File

@ -38,6 +38,7 @@ class SoundManager {
} }
func playSoundEffect(pathToFile: String, fileExtension: String, volumeLevel: Float){ func playSoundEffect(pathToFile: String, fileExtension: String, volumeLevel: Float){
self.isMusicPlaying = true
soundEffect = Bundle.main.url(forResource: pathToFile, withExtension: fileExtension) soundEffect = Bundle.main.url(forResource: pathToFile, withExtension: fileExtension)
do { do {
effectPlayer = try AVAudioPlayer(contentsOf: soundEffect!) effectPlayer = try AVAudioPlayer(contentsOf: soundEffect!)
@ -45,7 +46,11 @@ class SoundManager {
os_log("Could not load sound file %@", log: LOG, type: .error, pathToFile) os_log("Could not load sound file %@", log: LOG, type: .error, pathToFile)
} }
effectPlayer.volume += volumeLevel effectPlayer.volume += volumeLevel
effectPlayer.play() effectPlayer.prepareToPlay()
if self.isMusicEnabled == true {
effectPlayer.play()
UserDefaults.standard.set(false, forKey: "noMusic")
}
} }
func stopMenuMusic() { func stopMenuMusic() {