avfoundation - Sound board Swift 2 -


i trying make sound board app in swift , 3 out of 4 buttons crash app , other 1 nothing. doing wrong? new programming , trying follow tutorial doesn't work.

import avfoundation import uikit  class firstviewcontroller: uiviewcontroller  {      let soundfilesname = ["tacos", "what's supposed mean", "cube fist man", "giraffe"]      var audioplayers = [avaudioplayer]()      override func viewdidload() {         super.viewdidload()          //set audio player         sound in soundfilesname {              do{                  //try , somthing                 let url = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource(sound, oftype: "mp3")!)                 let audioplayer = try avaudioplayer(contentsofurl: url)                  audioplayers.append(audioplayer)             }             catch{                 //catch error thrown                 audioplayers.append(avaudioplayer())             }         }     }      @ibaction func buttontapped(sender: anyobject)     {         //get audioplayer thats corresponds button pressed          let audioplayer = audioplayers [sender.tag]         audioplayer.play()      } } 

update

running app through xcode on iphone 5 ios 9.0.2:

ios simulator:

please provide crash information getting when tapping on button.

also, put print in buttontapped check correct tag no, might accessing out of bounds elements array, not sure unless provide crash information.

@ibaction func buttontapped(sender: anyobject)     {        // check correct tag no        print("button tag \(sender.tag)")          //get audioplayer thats corresponds button pressed         let audioplayer = audioplayers [sender.tag]         audioplayer.play()      } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -