swift2 - Creating a soundboard app for iOS - stuck -
im extremely new ios development, , i'm trying make simple soundboard app.
i've watched various tutorials, , videos, can't seem code work in example. - maybe because video objective c or older version of swift - dont know.
https://www.youtube.com/watch?v=hzqcldd2x-a - seems easiest way i've found.
copying code:
import uikit import avfoundation class viewcontroller: uiviewcontroller { var sound01 = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("filename", oftype: "mp3")!) var audioplayer = avaudioplayer() override func viewdidload() { super.viewdidload() audioplayer = avaudioplayer(contentsofurl: sound01, error: nil) // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } } in version, doesn't errors: - yet in mine, get:
incorrect argument label in call (have 'contentsofurl:error:', expected 'contentsofurl:filetypehint:')
when use fix suggestion, becomes:
audioplayer = avaudioplayer(contentsofurl: sound01, filetypehint: nil) now error:
call can throw, not marked 'try' , error not handled
what doing wrong?
try replace line:
audioplayer = avaudioplayer(contentsofurl: sound01, error: nil)
with this:
audioplayer = try! avaudioplayer(contentsofurl: sound01!)
Comments
Post a Comment