Created
December 14, 2016 16:28
-
-
Save loldi/6d4b393342f1aa5b846bf5c259ff51ff to your computer and use it in GitHub Desktop.
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
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