# Play from online mp3

**URL:** https://qa.fmod.com/t/play-from-online-mp3/18182
**Category:** FMOD Engine
**Tags:** ios, android, cpp
**Created:** [January 5, 2022, 7:36pm UTC](https://qa.fmod.com/t/play-from-online-mp3/18182 "2022-01-05T19:36:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aliakhgar](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@aliakhgar](https://qa.fmod.com/u/aliakhgar)
#### Post date: [January 5, 2022, 7:36pm UTC](https://qa.fmod.com/t/play-from-online-mp3/18182/1 "2022-01-05T19:36:30Z")

</div>

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?  
Thanks.

---

<div class="post-metadata">

### Author: ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)
#### Post date: [January 7, 2022, 4:05am UTC](https://qa.fmod.com/t/play-from-online-mp3/18182/2 "2022-01-07T04:05:53Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![aliakhgar](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@aliakhgar](https://qa.fmod.com/u/aliakhgar)
#### Post date: [March 12, 2022, 8:14am UTC](https://qa.fmod.com/t/play-from-online-mp3/18182/3 "2022-03-12T08:14:16Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)
#### Post date: [March 16, 2022, 3:36am UTC](https://qa.fmod.com/t/play-from-online-mp3/18182/4 "2022-03-16T03:36:10Z")

</div>

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`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-sound.html#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

---

<div class="post-metadata">

### Author: ![aliakhgar](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@aliakhgar](https://qa.fmod.com/u/aliakhgar)
#### Post date: [March 16, 2022, 11:03am UTC](https://qa.fmod.com/t/play-from-online-mp3/18182/5 "2022-03-16T11:03:15Z")

</div>

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! 🙏🏻
