Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Load audio from external file?

edkeyte
Registered User
Quote
2022-02-15 12:33:52

Hi, is there a way to load an audio file such as .wav, mp3, ogg. from an external file at runtime?

More than likely only with scripting I would guess which I would find difficult to figure out.

I know we can load external images onto mesh as textures at runtime but wondering if sound files could be loaded in too.

Looking through the doc I see this:
ccbPlaySound("sound.wav");

But not sure how to turn it into a working script so that if on proximity with player then execute this command and hopefully play a sound file that is in the same directory as the game exe file.

Hopefully someone could help with this thank you.


csp-games
Guest
Quote
2022-02-15 13:29:21

You can easily test it, by adding a behavior (eg on key-press), to some node or another. There choose: special - execute javascript. There open the tiny text editor and paste the line mentioned above.


edkeyte
Registered User
Quote
2022-02-15 13:57:35

Thank you for your reply. Yes for some reason it didn't work the first time I tried but tried it again and it worked so thank you for that. I think possibly I didn't put quotes around the file name the first time which must be why it didn't work.
Thanks again.


csp-games
Guest
Quote
2022-02-24 22:49:21

Glad to see you got it working.


Robo
Guest
Quote
2022-02-25 02:02:06

You can separate sound nodes and separate volumes for each using this:

var node = ccbGetSceneNodeFromName("3D1");
ccbSetSceneNodeProperty(node, "SoundFileName", "");
ccbSetSceneNodeProperty(node, "SoundFileName", "tired4.ogg");
ccbSetSceneNodeProperty(node, "PlayMode", "play_once");

It needs to be reset each time with "" when playing once as once finished reverts back to play mode "nothing" and wont play again unless you update the playmode again...

The loading part is in the 'setSceneNodeProperty' setting and if its a new sound will then load it from the same directory as the EXE file (you can change its locations to whatever you like).

That's the loading part and if you wanted to load all sounds at the beginning you could run a forloop to update this with each sound (should work I think) and that way everything is loaded ready to go...although if you just load as needed (what I use in my game) at worst there is a slight lag on first playing the sound as its loading it and then plays it once loaded...but once loaded then its in memory and no lag at all......maybe Niko could fix this so it doesn't start playing until fully loaded ??


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inte?national" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact