Play from online mp3

Hi everyone,
I’ve been trying to play online mp3 file, First I download my file using libcurl and save it in memory, then try to play with OPEN_MEMEORY flag using FMOD.
My code working just fine when downloading all of my mp3 and give the correct length, But I tried to play while downloading and no luck. my best guess is that my length is not updating or FMOD just do not support it.
Is there any good example of how to play from memory progressively?

I think you should have a look at our net_stream example- it is in the core examples folder, in the case of Android that’s “{fmod api version}\api\core\examples\androidstudio\ndkbuild\net_stream”.

Essentially you need to call System::createSound with the flags FMOD_CREATESTREAM | FMOD_NONBLOCKING will allow you to pass a string url in as the “name_or_data” argument, and that should handle an online mp3.

Dear Jeff, I intend to manage networking on my own.
It’s because I’m downloading an encrypted mp3 file, which should be decrypted first, loaded into memory & played.
Long story short, can I still play STREAM & NONBLOCKING using memory pointer?

Presuming the file is encrypted in a way that allows data to be partially decrypted as the file is being downloaded, you will be able to play it back by manually filling a Sound's buffer with data as it becomes available. This would be the process:

  1. Create a new FMOD Sound with a FMOD_SOUND_PCMREAD_CALLBACK implemented (see user_created_sound example)
  2. Call System::playSound on the sound
  3. Start downloading the file
  4. Write the downloaded pcm data to a buffer
  5. In the pcmreadcallback, read from the buffer and write it to the *data parameter

Yes, I’m familiar with this mechanism from google oboe. I totally forgot about this, Thanks for such a quick replay. Your help means so much to me, Thanks again! :pray:t2: