I have an audio data stream coming in from a http response. I receive packets of bytes using the URLSessionDataDelegate method:
urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)
I have successfully played the audio after appending all the data packets into a single Data object, using an AVAudioPlayer
object and it's initWithData:
initializer method.
What I really want to do is start audio playback while data is still coming in - streaming audio effectively. I haven't seen any answers that seem elegant for this use-case.
Options I've seen are:
- Using the AudioToolbox: Audio File Stream Services & Audio Queues
- Using the NSStream API, writing to a file and playing audio from that file concurrently
How would I achieve audio streaming playback from the Data packets coming in?
AVPlayer
for that? – HygrophilousAVAssetResouceLoader
, but not deeply. I'm open to solutions with AVPlayer, what would that look like? – Magus