Created
November 5, 2018 02:54
-
-
Save gbertb/0fa251063a230fcba0be13007d712904 to your computer and use it in GitHub Desktop.
Play Audio after completing quiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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