【问题标题】: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")
}

【讨论】:

  • 不!你不明白。文件路径每次都可以改变。
  • 然后传递路径
  • 你可以计算路径并传递它
  • 你无法计算路径是什么问题
猜你喜欢
  • 2023-03-17
  • 2014-11-25
  • 1970-01-01
  • 2019-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多