Created
October 12, 2017 08:18
-
-
Save ahbou/064e4012397e9053e5ee3dc844ca2fcf to your computer and use it in GitHub Desktop.
Play .wav file in Swift
This file contains hidden or 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
let ringtonePath = URL(fileURLWithPath: Bundle.main.path(forResource: "sound", ofType: "wav")!) | |
do { | |
let ringtonePlayer = try AVAudioPlayer(contentsOf: ringtonePath) | |
try AVAudioSession.sharedInstance().setActive(true) | |
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord) | |
ringtonePlayer.volume = 1.0 | |
ringtonePlayer.play() | |
} catch { | |
print("Failed to initialize audio player \(error.localizedDescription)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
does't work for me