How do I import audio files and play them back on runtime?

0 favourites
From the Asset Store
Helping streamers give their viewers more excitement.
  • Hi Community,

    I am working on a Quiz project that needs to work with 1000's of sounds (i will not be able to import all these sounds for obvious memory and loading time reasons). Since this quiz game will be played on iOS devices, the "streaming audio plugin" or "play by url"option will not work due to the playback delay caused by safari when you stream outside audio. My best option would be to first import select sounds ON RUNTIME AND INTO the game and play them as standard imported local audio.

    Ashley, newt, How would i be able to achieve this?

    Thank you in advanced for the assistance.

  • Unless the file sizes are miniscule "thousands" really won't be feasible.

    Pode had a base64 plug, to load sounds from string, but the compression is not as good as the standards, and the plug was very basic.

  • Hi Community,

    I am working on a Quiz project that needs to work with 1000's of sounds (i will not be able to import all these sounds for obvious memory and loading time reasons). Since this quiz game will be played on iOS devices, the "streaming audio plugin" or "play by url"option will not work due to the playback delay caused by safari when you stream outside audio. My best option would be to first import select sounds ON RUNTIME AND INTO the game and play them as standard imported local audio.

    Ashley, newt, How would i be able to achieve this?

    Thank you in advanced for the assistance.

    There are no good way to do this as far as I know as you can't access the source of audio object for some weird reasons. So you need to make some workarounds to make it work.

    The only way I have figured out to do this, is to setup a variable path in the audio object and then you use this as the path to your audio files.

    However since the source requires a non extension path meaning the file can't be "sound.ogg" for instant, as C2 wont accept that it needs to be just "sound". So you need to make a functionality that extract the filename without the extension and then you add it together with the rest of the path so you get the complete path to the file.

    So the source when you are done should look like this:

    Path = "C:\Sounds\"  <--- Variable where you store the path to the files.
    Filename = "Sound1"  <--- This being the filename with the extension removed.
    
    In the Audio object source you add it together:
    Source: Path & Filename   <--- Read as (C:\Sounds\Sound1)
     [/code:50wmquii]
    
    So every time you want to load an audio file you have to update these two variable or just add it all in one depending on what you prefer. Its not really elegant but can't see any other way to do it.
  • Just import them all to C2, and set "Preload sounds" to "No". It won't download or decode any of the sounds on startup, it will load them on demand as you play them for the first time.

  • Ashley, the issue with this is that there over 10,000's sounds that sit on a private server. Currently the audio files are dynamically called to the game through an XML and played through the "audiostream" extension, which works by playing the audio through an URL, but currently with very bad lag on iOS devices.

    Is there a way that i can grab selected audio files through this XML and import them to the game (maybe through the invoke download action) in order to play them just like normal audio files?

    Is this possible?

  • nimos100, where can i find the audio object source in order to change the path?

  • Kyatric, is it possible to change the path of the sounds folder to another location (hosted in a server) in order to grab and play the audio files from here?

    If not, how can i import audio files on runtime from a server location and play them on demand?

    Many thanks for your continued assistance in these forums.

  • nimos100, where can i find the audio object source in order to change the path?

    You can't that's the whole problem. So you have to make a "fictional" source to bypass it. That's why I wrote in the original post, that its a mystery why you can't access the source of an audio object, because it should be fairly easy to do.

    But here is how you bypass it:

    The folder setting can be ignored, so doesn't matter if its "Sounds" or "Music" so don't worry about that.

    Notice that in the variable Audio_filename = "Sound_effect.ogg", it actually need to be "Audio_filename = "Sound_effect" otherwise it wont work. I just added the ".ogg" so you could see it was the filename. Since you can't load files without the extension you will always get the filenames with it, so you have to extract just the filename from you sound files which you can do with Tokencount and Tokenat if the files are in different locations, or just with tokenat if all the sounds are in the same folder.

    Since you say you have 10000 sounds, you of course have to add some functionality that can automate this for you. So you have to update the variables rather than trying to change the source of the audio object. But again its not a elegant solution, but the only way I have made it work.

  • nimos100, I see that your new audio path points to your local C: drive. Will this solution work for a folder hosted online?

    Thanks for your help...

  • nimos100, I see that your new audio path points to your local C: drive. Will this solution work for a folder hosted online?

    Thanks for your help...

    Not sure, so you would have to try to see if you can make the url so the filename can be added without the extension as that seems to be the important part when it comes to the source. But whether it will actually play it, even if you can get the filename and it will accept an non "<drive:>" format, is of course uncertain, as im pretty sure it weren't designed to work the way I did it in the first place, reading how its suppose to be used.

  • Ashley, i do not have the ability to import all 5,000 sounds.

    Is it possible to rename the root folder that the sounds are hosted on and make C2 point to that specific folder even if it is on another server?

    If not, how can i import an audio file on demand on runtime?

  • Ashley, rojohound, newt, wmsgva

    Is this something that can be accomplished?

    Perhaps, renaming the root folder where the sounds are hosted and make C2 point to that specific folder even if it is on another server. Any thoughts?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ashley's answer on your other thread seems reasonable.

  • nimos100 Thank you for your time and help.

    To confirm, this DID work for you and you were able to PLAY audio files that were sitting on your "local C: hard drive" and NOT the "sounds" folder within C2, correct?

    I tried this exactly, but was not able to make your workaround work, even for files sitting on my local C drive. I followed your example exactly as described. Do you think that you can share a simple .CAPX, just to see if i missed something.

    Thank you in advanced for your continued assistance...

  • nimos100 & Animate

    i tried the example as well without success .... a sample .CAPX would be a huge help!

    thanks!!!

    -Rik

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)