【问题标题】:How to play audio sound file in local container in swift ios xcode如何在 swift ios xcode 的本地容器中播放音频声音文件
【发布时间】:2017-01-27 08:49:10
【问题描述】:
我需要使用 Swift 之类的 Swift 从 iOS 中的用户本地文件系统容器播放音频声音文件
file:///Users/User/Library/Developer/CoreSimulator/Devices/EE8A846B-56D9-4B2B-9B52-FCC5CC16B7CA/data/Containers/Data/Application/C057C9A4-77DB-4615-AA78-C0A256ECD2D2/Documents/杜蒙.mp3
【问题讨论】:
标签:
ios
swift
xcode
audio
filesystems
【解决方案1】:
试试这个
//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")
}