Skip to content

Instantly share code, notes, and snippets.

@loldi
Created December 14, 2016 16:28
Show Gist options
  • Save loldi/6d4b393342f1aa5b846bf5c259ff51ff to your computer and use it in GitHub Desktop.
Save loldi/6d4b393342f1aa5b846bf5c259ff51ff to your computer and use it in GitHub Desktop.
override func viewDidLoad() {
}
override func motionBegan(_ motion: UIEventSubtype,
with event: UIEvent?){
print("moved")
do {
if let bundle = Bundle.main.path(forResource: "Smack", ofType: "mp3") {
let alertSound = NSURL(fileURLWithPath: bundle)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
try audioPlayer = AVAudioPlayer(contentsOf: alertSound as URL)
audioPlayer.prepareToPlay()
audioPlayer.play()
}
} catch {
print(error)
}
}
override func motionEnded(_ motion: UIEventSubtype,
with event: UIEvent?){
print("stoppped")
audioPlayer.stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment