Added sound to a program and now it crashes chrome

I am making a project for my son who loves trains. It is all working decent at this time but as soon as i added the sound to the project and im running one of the mouse presses with the sound on it crashes chrome. Is there a way around this or am i asking too much of the browser???
if you // the;
the program runs fine.

1 Like

Tried lowering the volume and trying a different file type instead of mp3 and still dont seem to have any luck. any ideas?

i know you not want to hear that:

-a- please clean up your coding so we find

  • where is the sound variable declared,
  • where is the sound file loaded
  • where is the sound started

your new multi-file.js structure is NOT HELPING
( we talked about that in your last topic, where we disagree HOW to avoid 3000 line coding )

sound you start like in setup
and directly pause it

later if you want to

  • start you need to check if running first so something like
    if ( ! mySound.isLooping() ) mySound.loop();

  • stop use pause again
    if ( mySound.isLooping() ) mySound.pause();

if you send play ( or loop ) on ( while ) one of your game conditions
or stop() or pause() in a other condition
you actually send it 50 times per sec to the computer OS

insofar YES

one of the things about modules is that you (can) make the sound code
in one module ( function ) ( even one extra file if you want to use it in a other program again )
but you need to call that from main ( and document that for other readers )

1 Like

1 Like

i thought you wanted me to separate everything into separate .js files so it would look cleaner.
I think this looks way better than the first game haahha.
so should i not call the audio in the draw function? how do i time it correctly then if it is meant to follow the rising of the barrior?

please link to where i say that?

i talked about to make:

function myfunction(){

and if you check your first program again, you might understand that a
mouseOver(x,y,w,h) { return true/false }
would have saved you lots of coding.

from draw you want to start sound?
yes, as i show the logic above,

    • only start if not running
    • only stop if running

Sorry, sometimes it not the easiest to understand all of your english.
I want to start the sound during a keypress when the angle variable is between a certain point.
if its outside that variable i want it to shut off.
i understand having it in draw has it starting and stopping 50 times a second like you said but the function for the angle is in draw so i tried putting it there so i wouldnt have to add more if statements.

I am still very new to this, I used the .js files to build certain parts of the program. train.js has the image information and puts it in multiple functions to show and move the train. this is what i thought you meant by modular.

1 Like

Now I have the sound starting to loop in setup. I have an if statement in draw stating if the angle variable is between -65 degrees and -2 degrees i want it to play, else i want it to pause.
now the audio is not crashing the program but it sounds all choppy and cracking.

example from a modified version of code you studied already???

and yes use extra myTools.js ( as long it is self contained and understandable )

Im trying to comprehend all of this but im like 2 weeks in, your programs are far more advanced than anything my brain can understand haha.

my other issue with this program is I have the railroad crossing barrier working with the up and down arrow presses and they are nice and fluid, but they have a set value they should not go past for the angle.
This doesn’t work unless it detects the key is release. Is it possible to have the program stop the function without key release

ok, just bookmark them for later

i did i have saved all your helpful links you sent me :grinning: