Mercurial > public > geoquiz
view GeoQuiz/Logic/PlaySound.swift @ 7:d945e52b0704
implement dynamic map
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Tue, 04 Oct 2022 18:54:24 +0200 |
parents | f31a61462e7a |
children |
line wrap: on
line source
// // PlaySound.swift // GeoQuiz // // Created by Dennis Concepción Martín on 22/9/22. // import Foundation import AVFAudio import UIKit class Sound { private var player: AVAudioPlayer? func play(_ filename: String) { guard let soundFileURL = Bundle.main.url(forResource: filename, withExtension: "wav") else { fatalError("Sound file \(filename) couldn't be found") } do { try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient) try AVAudioSession.sharedInstance().setActive(true) } catch { fatalError("Couldn't activate session") } do { player = try AVAudioPlayer(contentsOf: soundFileURL) player?.play() } catch { fatalError("Couldn't play sound effect") } } }