AVAudioPlayer swift beginner help need -


anyone kind me, create function code in swift3? have button pressed plays sound "push"

how can simplified when have lots of buttons, don't want add codes every button.

 var myaudio = avaudioplayer() // add sound         {             try myaudio = avaudioplayer(contentsof: nsurl(fileurlwithpath:                 bundle.main.path(forresource: "push", oftype: "mp3")!) url)         } catch {             nslog("no file!")          } //call sound myaudio.play() 

no made changes

i did    func play(name : string){          {             try myaudio = avaudioplayer(contentsof: nsurl(fileurlwithpath:                 bundle.main.path(forresource: name, oftype: "mp3")!) url)          } catch {             nslog("no file!")          }       }      @ibaction func buttonfirst(_ sender: uibutton) {          play(name: "push")         myaudio.play()      }      @ibaction func buttonsecond(_ sender: uibutton) {         play(name: "second")         myaudio.play()     } 

it working, got output: 2017-07-25 16:13:23.270349+0100 sound[1728:933024] [aqme] 254: aqdefaultdevice (173): skipping input stream 0 0 0x0

that problem?

i think forgot prepare

    var audioplayer = avaudioplayer()     let sound = url(fileurlwithpath: bundle.main.path(forresource: "sound", oftype: "mp3")!)      try! avaudiosession.sharedinstance().setcategory(avaudiosessioncategoryplayback)     try! avaudiosession.sharedinstance().setactive(true)      try! audioplayer = avaudioplayer(contentsof: sound)     audioplayer.preparetoplay()     audioplayer.play() 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -