Skip to content

Instantly share code, notes, and snippets.

@gbertb
Created November 5, 2018 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbertb/0fa251063a230fcba0be13007d712904 to your computer and use it in GitHub Desktop.
Save gbertb/0fa251063a230fcba0be13007d712904 to your computer and use it in GitHub Desktop.
Play Audio after completing quiz
func playAudio() {
do {
if let fileURL = Bundle.main.path(forResource: "Game Show Win", ofType: "wav") {
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileURL))
audioPlayer?.volume = 0.4
} else {
print("No file with specified name exists")
}
} catch let error {
print("Can't play the audio file failed with an error \(error.localizedDescription)")
}
let seconds = 0.2 //Time To Delay
let when = DispatchTime.now() + seconds
DispatchQueue.main.asyncAfter(deadline: when) {
self.audioPlayer?.play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment