我需要使用Swift之类的iOS中的用户本地文件系统容器播放音频声音文件
文件:///用户/用户/资源库/开发商/ CoreSimulator /设备/ EE8A846B-56D9-4B2B-9B52-FCC5CC16B7CA /数据/容器/数据/应用/ C057C9A4-77DB-4615-AA78-C0A256ECD2D2 /文档/ Dumont.mp3
答案 0 :(得分:0)
试试这个
//give your file path here in form of url
let urlstring = "file:///Users/User/Library/Developer/CoreSimulator/Devices/EE8A846B-56D9-4B2B-9B52-FCC5CC16B7CA/data/Containers/Data/Application/C057C9A4-77DB-4615-AA78-C0A256ECD2D2/Documents/Dumont.mp3"
let url = NSURL(string: urlstring)
do
{
self.player = try AVAudioPlayer(contentsOfURL: url)
player.prepareToPlay()
player.volume = 1.0
player.play()
}
catch let error as NSError
{
print(error.localizedDescription)
}
catch {
print("AVAudioPlayer init failed")
}