Discord
Login
Community
DARK THEME

Audio Handling

How do you guys do audio handling ? I meen i tried but it's bloody confusing and it gives me a bunch of errors,
I want to do simple car audio/sound handler i know i need to call it from init but how to swap sound like i have a different short loops of audio for engine idle, accel, reverse
I tried audio_obj_name.stop() before calling other sound i tried swaping a audio_obj_name.name but noting seems to work
I'm just stuck...

You can use the Audio component with JavaScript.

You may need to allow your browser to play sound automatically. (There are settings in the address bar in Firefox).

https://microstudio.io/i/Loginus/audio/

https://microstudio.io/i/Loginus/audio3/

@loginus thanks for response but i think you misunderstood my question.
I can play sounds but stoping and switching from sound to sound it's a different story the problem is for example car is idle and engine_idle loop is playing when i accelerate, car sound shuld switch to engine_accel but it doesn't untill instance of engine_idle is finished that's better case scenario in worse case audio is playing over audio and it's just mess.

Will this example help? https://microstudio.io/i/Loginus/audioengine/

@Loginus that is awesome I really like that project but I need something with bit more control and I came up with this:

audionameold = ''
audio.play = function(name,volume,pitch,pan,loop)

  if volume then volume else 1 end
  if pitch then pitch else 1 end
  if pan then pan else 0 end
  if loop then loop else 0 end
  
  if audionameold == name then
    return
  else
    sound.stop() 
    sound = audio.playSound(name,volume,pitch,pan,loop)
    audionameold = name
  end
end

So if anyone needs the function that can be called from update and played only once here it is.

Note: if not on loop you will need new sound before beeing able to play same sound again
I know about Warrning there is no way of fixing that att least to my knowledge right now

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community