在AVAudioEngine中从网络流数据,是否可能? [英] Stream data from network in AVAudioEngine, is it possible?
问题描述
我有一个应用程序,我使用 AVAudioEngine
通过 AVAudioPlayerNodes
从本地文件系统播放文件 AVAudioFiles
。这非常合适。
现在我想启用我的设置,也支持从互联网上的服务器流式传输MP3文件。
到目前为止我尝试了什么
我希望我可以从<$创建某种缓冲区c $ c> NSURL 指向网络地址的对象,然后我可以使用我的 AVAudioPlayerNode
。
我搜索了 Stack Overflow 和互联网一般但没有找到任何关于如何实现这一目标的好建议。<我知道 AVAudioEngine
阵容包括:
>
AVAudioFile
或 AVAudioBuffer
的音频。我今天已经使用 AVAudioFile
进行本地文件设置。AVAudioFile ,这是用于本地文件。 'AVAudioFile'是使用'NSURL'创建的,所以我尝试使用指向服务器上的MP3文件的URL,就像在Playground中一样:
var fileError:NSError? = nil
let file = AVAudioFile(forReading:someURL,error:& fileError)
if fileError!= nil {
fileError
}
奖励我这个错误:
错误Domain = com.apple.coreaudio.avfaudio Code = 2003334207操作无法完成。(com.apple.coreaudio.avfaudio error 2003334207.)UserInfo = 0x7fbfab424480 {failed call = ExtAudioFileOpenURL((CFURLRef)fileURL,& _extAudioFile)}
- AVAudioPCMBuffer ,这是我希望使用的类,但我找不到用数据实例化的方法。
我的问题(只是为了说清楚: - ))
你们中有谁聪明的人知道如何使用 AVAudioEngine
从互联网服务器上传输MP3文件?
或者我应该放弃并使用 AVPlayer
为此?
期待收到您的回复。
Apple的文档没有说明它是否可以与在线托管的mp3一起使用,但是一旦我尝试初始化 AVAudioFile
使用mp3网址,它会立即崩溃并导致致命异常。我认为这可以回答你的问题。
I have an app in which I use AVAudioEngine
for playing files from the local file system by using AVAudioPlayerNodes
and AVAudioFiles
. This works perfectly fine.
Now I would like to enable my setup to also support streaming of MP3 files from a server on the internet.
What I've tried so far
My hope was that I could create some sort of buffers from NSURL
objects pointing to network addresses, which I could then use with my AVAudioPlayerNode
.
I've searched Stack Overflow and the internet in general but haven't found any good tips on how to achieve this.
I know that the AVAudioEngine
lineup consists of:
- AVAudioPlayerNode, which can play audio from an
AVAudioFile
or aAVAudioBuffer
. I already useAVAudioFile
for my "local file setup" today. AVAudioFile, which is to be used for local files. An 'AVAudioFile' is created with an 'NSURL' so I've tried with an URL that points to a MP3 file on a server like so in a Playground:
var fileError: NSError? = nil let file = AVAudioFile(forReading: someURL, error: &fileError) if fileError != nil { fileError }
which rewards me with this error:
Error Domain=com.apple.coreaudio.avfaudio Code=2003334207 "The operation couldn’t be completed. (com.apple.coreaudio.avfaudio error 2003334207.)" UserInfo=0x7fbfab424480 {failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)}
- AVAudioPCMBuffer, which is the class I was hoping to use, but I can not find any way to instantiate it with data.
My question (just to make it clear :-))
Does any of you bright people out there know how to use AVAudioEngine
for streaming MP3 files from a server on the internet?
Or should I just give up and use AVPlayer
for this?
Looking forward to hearing from you.
Apple's documentation doesn't specify if it can work with a mp3 hosted online but as soon as I try to initialize an AVAudioFile
with a mp3 url it crashes instantly with a fatal exception. I think that answers your question.
这篇关于在AVAudioEngine中从网络流数据,是否可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!