I want to play an audio file when a key on my custom keyboard is clicked using swift. I've tried this, however, have had no luck. How can I make this work? Is playing a custom audio sound on a keyboard action possible?
func btnPressed(sender: AnyObject)
{
var btn = sender as UIButton
var stringToInsert=""
var proxy = self.textDocumentProxy as UIKeyInput
switch (btn.tag)
{
case 10:
stringToInsert = "a"
if let path = NSBundle.mainBundle().pathForResource("8bit", ofType: "wav") {
audioPlayer = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: path), fileTypeHint: "wav", error: nil)
if let sound = audioPlayer {
sound.prepareToPlay()
sound.play()
println("hello")
}
}
}
proxy.insertText(stringToInsert)
}
}
Aucun commentaire:
Enregistrer un commentaire