如何从文件目录访问音频文件?

Jan*_*Jan 1 avaudioplayer ios swift

我有一个音频文件存储在文档目录中,现在我需要获取该音频文件并进行一些加密/解密。我想要这样:

let audiofile = get audio file from document directory // This is what i want

encrypt(audiofile)// I have AES technique, This is not my question.
Run Code Online (Sandbox Code Playgroud)

JAc*_*Ack 5

这很简单!!!

就像下面的代码:

var paths: [AnyObject] = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)

let audiofilePath = paths[0].stringByAppendingString("/myaudio.mp3")

//Write name of your audio at **myaudio.mp3**

//now you can use anywhere audiofilePath as String like

let audiourl : NSURL = NSURL((fileURLWithPath: audiofilePath))

//or you can make asset like

let assets = AVAsset(URL: NSURL(fileURLWithPath: audiofilePath))
Run Code Online (Sandbox Code Playgroud)

享受编码的乐趣,如果有任何帮助,请问我。