如何从 swift 中具有单独位置 url 和资源 url 的服务器直播音频?
How to live stream audio from server in swift which has separate location url and resource url?
我正在开发来自第三方 API 提供商 (www.mndigital.com) 的音乐应用程序。 API 提供商为每首歌提供了 30 秒的演示。演示应用程序的位置以这种格式给出
"SampleLocations": [
{
"Location": "rtmp://mn-ecn-prd-rtmp.mndigital.com",
"Resource": "mp3:/spl/382/071/327/spl_024?48d882e51ff49ca3806e4b63d90b926556349db16cecf61947a8eb9a44f9bee3bf7d",
"Type": "s_mp3"
},
{
"Location": "rtmp://mn-ecn-prd-rtmp.mndigital.com",
"Resource": "mp4:/spl/382/071/327/spl_029.mp4?48d882e51ff49ca3806e4b63d90b926556349db16cecf61947a8eb9a44f9bee3bf7d",
"Type": "s_mp4"
}
],
另外,API 提供者在条款和条件中说样本必须来自服务器 streamed live
和 should not be saved locally
。
经过几个小时的搜索,我发现这种格式适用于在 flash 播放器中播放音频。但在 IOS 中不支持 flash 播放器。
即使要使 AVPlayer
正常工作,我们也只需要更新后的 swift 语法中的一个 url
do {
let url = "http://yourdomain.com/file.mp3"
let fileURL = NSURL(string:url)
let soundData = NSData(contentsOfURL:fileURL!)
self.audioPlayer = try AVAudioPlayer(data: soundData!)
audioPlayer.prepareToPlay()
audioPlayer.volume = 1.0
audioPlayer.delegate = self
audioPlayer.play()
} catch {
print("Error getting the audio file")
}
所以我不知道如何在 swift 中播放这种 url。谁能提出解决方案。
我正在使用 swift 2.0 xcode 7.1.1。我的部署目标是 IOS 8.0 及更高版本
经过长时间的搜索,我发现rtmp文件无法在苹果设备上播放,因为苹果不支持flash payers。无法播放这些格式的 URL 提供的任何数据。
我正在开发来自第三方 API 提供商 (www.mndigital.com) 的音乐应用程序。 API 提供商为每首歌提供了 30 秒的演示。演示应用程序的位置以这种格式给出
"SampleLocations": [
{
"Location": "rtmp://mn-ecn-prd-rtmp.mndigital.com",
"Resource": "mp3:/spl/382/071/327/spl_024?48d882e51ff49ca3806e4b63d90b926556349db16cecf61947a8eb9a44f9bee3bf7d",
"Type": "s_mp3"
},
{
"Location": "rtmp://mn-ecn-prd-rtmp.mndigital.com",
"Resource": "mp4:/spl/382/071/327/spl_029.mp4?48d882e51ff49ca3806e4b63d90b926556349db16cecf61947a8eb9a44f9bee3bf7d",
"Type": "s_mp4"
}
],
另外,API 提供者在条款和条件中说样本必须来自服务器 streamed live
和 should not be saved locally
。
经过几个小时的搜索,我发现这种格式适用于在 flash 播放器中播放音频。但在 IOS 中不支持 flash 播放器。
即使要使 AVPlayer
正常工作,我们也只需要更新后的 swift 语法中的一个 url
do {
let url = "http://yourdomain.com/file.mp3"
let fileURL = NSURL(string:url)
let soundData = NSData(contentsOfURL:fileURL!)
self.audioPlayer = try AVAudioPlayer(data: soundData!)
audioPlayer.prepareToPlay()
audioPlayer.volume = 1.0
audioPlayer.delegate = self
audioPlayer.play()
} catch {
print("Error getting the audio file")
}
所以我不知道如何在 swift 中播放这种 url。谁能提出解决方案。
我正在使用 swift 2.0 xcode 7.1.1。我的部署目标是 IOS 8.0 及更高版本
经过长时间的搜索,我发现rtmp文件无法在苹果设备上播放,因为苹果不支持flash payers。无法播放这些格式的 URL 提供的任何数据。