Detecting if audiofile plays

In scene A user can click button to play audio file.
From scene A user van navigate to scene B.
How can I detect in scene B if the audio file is playing (triggered)? I want to use this in a function to show/not show a “stop sound button”.
Any help much appreciated!
Hans

Hi Hans. @info9

Assuming your Element ID is audio.

Use the following code to detect if audio is playing (make the variables global because of scene changes and run it on scene load):

window.audio = document.getElementById("audio"); // create audio variable globally i.e belonging to browser. Now you can access it anywhere.

Do this perhaps in Scene 1 on scene load.

Then in scene 2 on scene load:

if (!audio.paused) { // check if playing !paused = playing
    // code here
    document.getElementById("STOP BUTTON").style.display = "inline"; // example
}

Then for your stop button you can add another script on mouse click to STOP the audio.

audio.pause();

Because the variable is global it can be accessed in any scene. Make sure you declare this audio file in your scene 1.

Hi, thank you for your reply! The only thing is HOW do I give an ID to the audio. Right now I have a icon with a onclick to start audio. Audio is chosen by Hype dropdown audio chooser. I have no idea how to find out its ID or to give it an ID.
Any suggestions on this?
Thank you!

You cannot get this information at the moment.

I have put in a request for it : here

The way @DBear suggests is that you create your Audio element in code first. This is the only way you have access to the audio.

See :

1 Like

Thank you. I just found that out myself too. I can live with creating my own audio element first.

1 Like