Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6151125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:43:31+00:00 2026-05-23T19:43:31+00:00

Been banging my head against this problem all morning. I have setup a connection

  • 0

Been banging my head against this problem all morning.

I have setup a connection to a datasource which returns audio data (It is a recording device, so there is no set length on the data. the data just streams in. Like, if you would open a stream to a radio)

and I have managed to receive all the packets of data in my code. Now I just need to play it. I want to play the data that is coming in, so I do not want to queue a few minutes or anything, I want to use the data I am recieving at that exact moment and play it.

Now I been searching all morning finding different examples but none were really layed out.

in the

  • (void)connection:(NSURLConnection )connection didReceiveData:(NSData)data {

function, the “data” package is the audio package. I tried streaming it with AVPlayer, MFVideoPlayer but nothing has worked for me so far. Also tried looking at mattgallagher’s Audiostreamer but still was unable to achieve it.

Anyone here can help, has some (preferably) working examples?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:43:32+00:00Added an answer on May 23, 2026 at 7:43 pm

    Careful: The answer below is only valid if you receive PCM data from the server. This is of course never happens. That’s why between rendering the audio and receiving the data you need another step: data conversion.

    Depending on format, this could be more or less tricky, but in general you should use Audio Converter Services for this step.

    You should use -(void)connection:(NSURLConnection )connection didReceiveData:(NSData)data only to fill a buffer with the data that comes from the server, playing it should not have anything to do with this method.

    Now, to play the data you ‘stored’ in memory using the buffer you need to use RemoteIO and audio units. Here is a good, comprehensive tutorial. You can remove the “record” part from the tutorial as you don’t really need it.

    As you can see, they define a callback for playback:

    callbackStruct.inputProc = playbackCallback;
    callbackStruct.inputProcRefCon = self;
    status = AudioUnitSetProperty(audioUnit, 
                                  kAudioUnitProperty_SetRenderCallback, 
                                  kAudioUnitScope_Global, 
                                  kOutputBus,
                                  &callbackStruct, 
                                  sizeof(callbackStruct));
    

    and playbackCallback function looks like this:

    static OSStatus playbackCallback(void *inRefCon, 
                              AudioUnitRenderActionFlags *ioActionFlags, 
                              const AudioTimeStamp *inTimeStamp, 
                              UInt32 inBusNumber, 
                              UInt32 inNumberFrames, 
                              AudioBufferList *ioData) {
    
        for (int i = 0 ; i < ioData->mNumberBuffers; i++){      
            AudioBuffer buffer = ioData->mBuffers[i];
            unsigned char *frameBuffer = buffer.mData;
            for (int j = 0; j < inNumberFrames*2; j++){
                frameBuffer[j] = getNextPacket();//this here is a function you have to make to get the next chunk of bytes available in the stream buffer
            }
        }
    
        return noErr;
    }
    

    Basically what it does is to fill up the ioData buffer with the next chunk of bytes that need to be played. Be sure to zero out (silence) the ioData buffer if there is no new data to play (the player is silenced if not enough data is in the stream buffer).

    Also, you can achieve the same thing with OpenAL using alSourceQueueBuffers and alSourceUnqueueBuffers to queue buffers one after the other.

    That’s it. Happy codding!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been banging my head against a wall with this code all morning and
I have been banging my head against this problem for days, and searched exhaustively
I have been banging my head on this one all day. The C++ project
This is to all the C# gurus. I have been banging my head on
I've been banging my head against the wall on this one. I have a
I've been banging my head against this for a week. I have a page
Okay, so I've been banging my head against this problem for a couple of
I've been banging my head against for wall for a while with this one.
been banging my head against this one for a while. For a CSS redesign
I've been banging my head against a wall for about an hour on this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.