ios - Playing system sounds using Swift -


I'm trying to play a sound when a button is pressed using the system sound I get the error: "the fatal error was unexpectedly found open no option unexpectedly from" I tried debugging, and I believe that error var ref on line "Roarkaif" There is a custom sound that I have included in my project. I'm halfway tall and I appreciate the tips! Thank you

  var soundID: SystemSoundID = SystemSoundID () var mainBundle: CFBundleRef = CFBundleGetMainBundle () var Ref: CFURLRef = CFBundleCopyResourceURL (mainBundle, "roar.aif", zero, zero) as CFURLRef ! println ( "Here's your ref: \ (ref)") AudioServicesCreateSystemSoundID (Reference, & amp; soundID) AudioServicesPlaySystemSound (soundID)  

I believe that the right way is to use the file type in the third parameter:

  var soundID: SystemSoundID = 0 var mainBundle: CFBundleRef turn = CFBundleGetMainBundle () are ref: CFURLRef = CFBundleCopyResourceURL (mainBundle, CFSTR ( "roar"), CFSTR ( "AIF"), nil) {println ( "here's your ref: \ (ref)") AudioServicesCreateSystemSoundID ( Reference, & soundID) AudioServicesPlaySystemSound (soun DID)} else {println ("could not find sound file")}  

Do you really have roar.aif file and not roar.aiff?

Make sure that the file is for adding as a fourth parameter, then not in a subdirectory

.


Comments