【发布时间】:2018-01-25 05:45:11
【问题描述】:
我正在尝试使用此代码使用 AVAudioPlayer 播放音频文件:
let urlString = "http://192.168.1.19:8080/download/2"
let url = URL(string: urlString)!
print("the url = \(url)")
do {
let data = try Data.init(contentsOf: url)
self.audioPlayer = try AVAudioPlayer.init(data: data)
self.audioPlayer.prepareToPlay()
self.audioPlayer.play()
} catch {
print("couldn't load file")
}
音频格式为 Ogg Vorbis (.ogg),总是无法加载。播放此 .ogg 文件的任何解决方案?
【问题讨论】:
-
该答案已弃用,链接无法打开,并且已经 5 年了,甚至在 Swift 发布日期之前
-
所有链接都对我有用,尽管您可能不想使用“Precompiled Ogg Vorbis Libraries for iOS”链接后面的预编译框架,因为这些都是旧的。然而,GitHub 项目的最终链接包含更新版本。注意支持bridge Objective-C code into Swift
-
我无法重现 .ogg 文件(可能不支持),所以我不得不将其转换为 mp3(
ffmpeg处理媒体文件的好工具)。 -
我也想玩.ogg
标签: ios swift audio avaudioplayer