How to load an audio file in the Playground?

I want to load a local file in the playground. Started by adding it to the "resources" directory of "navigator".
To make sure I get the correct full path, I did a drag and drop to the source-code and got the complete string path.

This doesn't seem to be the correct way of doing it. The error I got is:


Playground execution terminated: An error was thrown and was not caught:

Error Domain=NSCocoaErrorDomain Code=264 "The file “click.wav” couldn’t be opened because the text encoding of its contents can’t be determined." UserInfo={NSFilePath=/foobar/click.wav}


Here's the source:

let url = URL(fileURLWithPath: "/foobar/click.wav")


Have in mind that for brevity used `foobar` in the file path.
The library I'd like to pass the variable expects a `URL`!

Replies

This seems to work, but there might be other ways:

let url = Bundle.main.url(forResource: "click", withExtension: "wav")