我在模拟器中测试我的应用程序.
我正在下载文件并获取它的本地方式,如下所示:
文件:///Users/administrator/Library/Developer/CoreSimulator/Devices/4CDF286B-543F-4137-B5E2-C312E19B992F/data/Containers/Data/Application/E5F13797-A6A8-48A1-B3C3-FBC3D7A03151/Documents/4d13e04980d3.mp3
现在我想用AVAudioPlayer播放这个文件,但我总是收到这个错误:
file:/// Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"
比赛代码:
var alertSound = NSURL(fileURLWithPath: "file:///Users/administrator/Library/Developer/CoreSimulator/Devices/4CDF286B-543F-4137-B5E2-C312E19B992F/data/Containers/Data/Application/E5F13797-A6A8-48A1-B3C3-FBC3D7A03151/Documents/4d13e04980d3.mp3") print(alertSound) var error:NSError? do { try audioPlayer = AVAudioPlayer(contentsOfURL: alertSound) audioPlayer.prepareToPlay() audioPlayer.play() } catch { print(error) }
我该怎么玩呢?