Playing Streaming Audio in iOS Application

Dheeraj Kumar Gunti

Reading Time : ( words)

Audio is the greatest thing now happening in the mobile world. With the cool stuff in CoreAudio framework, your apps can have great audio experience. Core Audio streaming is particularly useful for scenarios such as playing live audio from web. Lets start with a small example of how we can leverage CoreAudio framework for streaming an audio from web.

First we will have some initalizations. In the below code we are trying to have a audio url from where we will be streaming the audio. We are using AudioFileStream class which is the key in CoreAudio framework. Create an object of AudioFileStream. After that we are creating an object for OutputAudioQueue which we will use to allocate number of buffers that we use to fill in the data. Once the buffer is filled it is enqueued and when the OutputAudioQueue finished then the completed event will be raised.

We will be creating an instrance of AudioFileStream here and we are specifying the type of the audio as MP3.

AudioFileStream has two important events,

  1. PacketDecoded
  2. PropertyFound

-- Packet Decoded --

-- Property Changed --

Using NSUrlSession we are trying to get the default session configuration based on our filestream and executing task using the audio url.

We are creating a SessionDelegate which is used in whenever the stream receives data it parses the bytes.

Run the application and see the magic of CoreAudio framework done to your application.

More about Core Audio

Happy Coding....