Stream data from network in AVAudioEngine, is it possible?
Asked Answered
A

1

10

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 a AVAudioBuffer. I already use AVAudioFile 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.

Agglutinate answered 16/6, 2015 at 8:41 Comment(2)
"Or should I just give up and use AVPlayer for this?" Yes.Shavon
Thanks @TomHarrington. Short and to the point :-)Agglutinate
B
1

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.

Billington answered 8/10, 2015 at 20:15 Comment(1)
It does right. Not exactly the answer I was hoping for but thank you for your time and answer.Agglutinate

© 2022 - 2024 — McMap. All rights reserved.