xcode - Audio Code docent work in Swift 2 -
can me correcting code. know has changed because of swift 2.
import uikit import avfoundation class viewcontroller: uiviewcontroller { @iboutlet var pauseplay: uibutton! var buttonaudioplayer = avaudioplayer(contentsofurl: nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("buttonaudio", oftype: "mp3")!), filetypehint: nil) }
what you're looking shown below. need declare instance of avaudioplayer
, nsurl
@ instance level
class viewcontroller: uiviewcontroller { var buttonaudiourl = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("songname", oftype: "mp3")!) var buttonaudioplayer = avaudioplayer() override func viewdidload() { { try buttonaudioplayer = avaudioplayer(contentsofurl: buttonaudiourl, filetypehint: nil) } catch { print("errorin do-try-catch") } } @ibaction func() { buttonaudioplayer.play() } }
Comments
Post a Comment