# Playing bundled music files

**URL:** <https://qa.fmod.com/t/playing-bundled-music-files/20206>\
**Category:** FMOD Engine\
**Tags:** android, cpp\
**Created:** [May 9, 2023, 3:14pm UTC](https://qa.fmod.com/t/playing-bundled-music-files/20206 "2023-05-09T15:14:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiyongman](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jiyongman](https://qa.fmod.com/u/jiyongman)\
**Post date:** [May 9, 2023, 3:14pm UTC](https://qa.fmod.com/t/playing-bundled-music-files/20206/1 "2023-05-09T15:14:14Z")

</div>

Hello,

I am wondering if there is a built-in method within the FMOD API to play game background music files from a bundled file such as a .zip file or a custom file. Specifically, I have combined multiple mp3 files into a single file by copying all of their bytes, and I am wondering if FMOD has a function for playing bundled files like this.

If this feature is not available in the FMOD API, I would greatly appreciate any guidance or hints you could provide to help me achieve this task using the FMOD\_CREATESTREAM mode instead of FMOD\_CREATESAMPLE or FMOD\_CREATECOMPRESSEDSAMPLE, as this would allow me to conserve memory.

Thank you for your time and assistance.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [May 11, 2023, 12:27am UTC](https://qa.fmod.com/t/playing-bundled-music-files/20206/2 "2023-05-11T00:27:15Z")

</div>

Hi,

> [@jiyongman](#):
>
> Specifically, I have combined multiple mp3 files into a single file by copying all of their bytes, and I am wondering if FMOD has a function for playing bundled files like this.

FMOD doesn’t have any “easy” way of doing this i.e. no one function that will just scan your bundled files and figure out the length, format, etc. of each, but there are still ways to go about it - the easiest way would probably be to use [`FMOD_SOUND_CREATEEXINFO`](https://www.fmod.com/docs/2.02/api/core-api-system.html#fmod_createsoundexinfo) to specify a `fileoffset` and `length` for a given audio file in the bundle. Streaming should be as simple as adding `FMOD_CREATESTREAM` as a mode for the sound. Fundamentally though, you do need to know the location/length of all the sub-files in your bundled file.

However, FMOD comes with a soundbank format called FMOD Sound Bank (FSBank/FSB), which would allow you to encode and compress your BGM, and to load/stream specific subsounds from the FSBank. If this sounds like it’d be useful, I’d recommend taking a look at the `fsbank_api` example included with the FMOD Engine download, as well as the [FSBank API Documentation](https://www.fmod.com/docs/2.02/api/fsbank-api.html).

---

<div class="post-metadata">

**Author:** ![jiyongman](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jiyongman](https://qa.fmod.com/u/jiyongman)\
**Post date:** [May 11, 2023, 2:58pm UTC](https://qa.fmod.com/t/playing-bundled-music-files/20206/3 "2023-05-11T14:58:30Z")

</div>

Thank you for reminding me about the trick using `FMOD_CREATESOUNDEXINFO`.  
I actually tried that a while ago but completely forgot about it until today, haha.

I completely agree that the **FSB** format is fantastic, and I will definitely make proactive use of it in my future projects.  
However, at the moment, I have to deal with a bunch of bundle and .zip files.

I was wondering if you could provide me with some tips or advice on playing files in a .zip file.  
Initially, I thought it might be possible with the `funopen()` trick, but I just realized that `FMOD_System_CreateSound()` doesn’t accept a file pointer as an argument.

So, the only solution I can think of is directly loading a .mp3 file from the .zip file into memory and creating a sound with the `FMOD_OPENMEMORY` mode.  
While this approach will work, it will consume more memory due to the source bytes.

Do you have any other ideas or suggestions?

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [May 12, 2023, 12:16am UTC](https://qa.fmod.com/t/playing-bundled-music-files/20206/4 "2023-05-12T00:16:33Z")

</div>

Unfortunately, I don’t have any specific suggestions for streaming from a .zip file. Streaming from a a bundle of .mp3 files that have simply been concatenated is feasible, but FMOD doesn’t support handling .zip files - you would need an external library to decompress the file instead. That said, FMOD does allow you to piggyback on its own file system routines with your own callbacks using [`System::attachFileSystem`](https://www.fmod.com/docs/2.02/api/core-api-system.html#system_attachfilesystem), which you could use alongside a third party library to handle your .zip file(s).

---

<div class="post-metadata">

**Author:** ![jiyongman](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jiyongman](https://qa.fmod.com/u/jiyongman)\
**Post date:** [May 12, 2023, 12:55pm UTC](https://qa.fmod.com/t/playing-bundled-music-files/20206/5 "2023-05-12T12:55:10Z")

</div>

Thank you so much for your valuable input!  
I may be mistaken, but at first glance, `System::attachFileSystem` seems to be a kind of version of `funopen()` in the context of **FMOD**.  
I’m really excited to give it a try.  
Once again, I truly appreciate your advice and guidance.
