core audio - AVAudioFile in Swift Playground results in "error -54" -


i decided have play avaudioplayer in swift playground. following code works fine in normal swift project, returns following error when running in playground (in assistant editor):

2015-05-12 00:08:04.374 avaudiofile[2481:141158] 00:08:04.374 error: avaudiofile.mm:266: avaudiofileimpl: error -54

here code:

import cocoa import avfoundation  var audiofileurl = nsurl(fileurlwithpath: "/users/scooby/desktop/song.wav") var error: nserror? var audiofile = avaudiofile(forreading: audiofileurl, error: &error) 

printing error out comes with:

error domain=com.apple.coreaudio.avfaudio code=-54 "the operation couldn’t completed. (com.apple.coreaudio.avfaudio error -54.)" userinfo=0x7fa8c0736f70 {failed call=extaudiofileopenurl((cfurlref)fileurl, &_extaudiofile)}

just can't figure out why error in playground. ideas @ all?

thanks!

xcode 6

  1. open playground in finder ("show package contents")
  2. create "resources" folder inside
  3. add file in folder
  4. quit , relaunch playground

to use file:

let audiofileurl = nsbundle.mainbundle().urlforresource("myfile", withextension: "wav") var error: nserror? let audiofile = avaudiofile(forreading: audiofileurl, error: &error) 

xcode 7

no need workaround anymore.

open playground's project navigator (cmd+1) drag & drop file(s) existing "resources" folder.

to use file:

do {     if let audiofileurl = nsbundle.mainbundle().urlforresource("myfile", withextension: "wav") {         let audiofile = try avaudiofile(forreading: audiofileurl)         // use audiofile here     } } catch let error nserror {     print(error.localizeddescription) } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -