How to stop a sound and detect if it's playing?


High Fidelity is so frustrating.
I need to stop a sound that is playing. So looking on the wiki. But the sound section is so incomplete as possible. And the worse thing is that i know the info is on the old docs page. But that is not available anymore (pretty stupid move)

So, i tried to search in example scripts. i tried to open the wayback to decypt the garbled info. but that generate error and not load the pages at all. In other words, again nothing done because simple tasks are the hard tasks

So how do you stop a sound in high fidelity ?

Also detecting if a sound is playing with isPlaying seems to generate errors. In this case again the old docs page where [pretty clear around this parts.

Again, what is the URL of the old docs page.
i cannot believe the removed it complete.

Wayback is working again, decrypting the spaghetti code.
Because the crippled reading ,
there are mabye some errors. But better then what’s on the wiki

  • var injector = Audio.playSound(options);

  • injector.restart();
    stops playback and restarts from beginning - useful for repeated sounds

  • injector.stop();
    stops playback immediately

  • injector.getLoudness();
    returns the loudness in last frame as a value between 0 and 1.0

  • injector.finished.connect(function();
    your injector is done playing"

  • injector.isPlaying();

Now, let’s see if i can finish what i wanted today

Now i only need to fix error.

[01/26 20:31:38] [CRITICAL] [hifi.scriptengine] "[UncaughtException] TypeError: Result of expression ‘audioDoorOpenInjector’ [undefined] is not an object. in Entities 1:86\n[Backtrace]\n


Seems wiki is updated, or i have a good search day.

But i have still a problem, I check if audio is playing with.

var audioDoorOpenInjector;


if (audioDoorOpenInjector.isPlaying())



This global idea. the IsPlaying is inside a function. Variable is global. playsound is in other function. This check can happen before audio ever started to play. I still get error.

[hifi.scriptengine] "[UncaughtException] TypeError: Result of expression 'audioDoorOpenInjector' [undefined] is not an object. in Entities 1:86\n[Backtrace]

Off course it’s not object. because it’s injector. Does high fidelity have a bug so it cannot handle IsPlaying before you have used playsound ? That would be bad. or is something else wrong.

Anyway, cannot do anything. I do not see anything wrong to, Except a possiblke problem with isPlaying is not doing something correct when variable have not assigned injector.


The reason you got the exception is because that variable is null. It has to be initialized with an instance of an audio injector. So somewhere in your script you must have played the sound, hence something like this was coded:

var audioDoorOpenInjector = Audio.playSound(…)

You have to save the audio injector object reference that playSound returned, and then use it later to modify the properties of that injector.


Ok, thanks for hinmts.

The real solution is to just add a check.

if (typeof audioDoorOpenInjector != "undefined")

This seems to work. (for now)
DOing more testing with this code.


Ah quite right. I missed this sentence where you wrote the some other event function could be called before the sound was started. So, yes, checking for a valid injector reference is valid is needed. To be formal, it would be better to check if the variable is an instance of an audio injector, so from this:
if (typeof audioDoorOpenInjector != "undefined")

change it to this:
if (audioDoorOpenInjector instanceof AudioInjector)


Thanks. testying it with that.
Problem with javascript. it’s a strange language.
Not sure if C# is better to compare it with soemthing other new.
Am used to older languages, so take soem times to learn the new ways.

Anyway, your solution is failing.

[hifi.scriptengine] "[UncaughtException] ReferenceError: Can't find variable: AudioInjector in Entities

putting my line back.