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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -