system.util.playSoundClip only work on gateway

I make a soundplay program. I test it on gateway.it’s ok.
but when I use other computers to connect this gateway.I can’t heard anything from the new computer.

Perspective or Vision? In Perspective, it can’t be a local sound file. It has to be a URL served from elsewhere. Using Webdev or your own infrastructure.

(I vaguely recall this not working in Perspective until recently… the version you are using might matter.)

1 Like

Hello, experts.thank you for your answer. I am using both perspective and version.my audio was played by scripts,not on graph.

Tag events run on the gateway. So that’s where the sound plays. If you want to play the sound in Vision, you’ll need to use a tag change script in the project’s client events and play the sound from there. In Perspective, you’ll need to bind the tag to a custom session property, and play the sound from a propertyChange event on that custom property.

thank you very much.with your answer,I have solved the version sound problem. but at perspective ,it still not work.I tried two places.image .with this way ,I use the script:system.perspective.sendmessage().this way ,only gateway sound,other remote clients no sound. 2. I tried image ,even the gateway no sound.I use the system.util.sendmessage()

All scripting in Perspective happens on the gateway, so playSoundClip will never work for what you're trying to do.

For now, the only way to have a Perspective client play a sound is using the workaround mentioned in this thread:

We're considering adding a scripting solution or some other way to actually play a sound from a Perspective component, but for now, that's the solution.

2 Likes

thank you very much for your advise.I tried the way as your way. It’s work when the page is opened, so I put the iframe on the top solid windows ,so every page could play the audio when alarm comes.:orange_heart::orange_heart::orange_heart::orange_heart:

A post was split to a new topic: system.util.playSoundClip not loading local file

Is this something that has been fixed? I have the script below that will run through my laptop when it is set as the gateway but will not work on other clients. I am on perspective, the link works on both devices when entered into the URL but when another client is opened on a different machine we do not get audio on anything other than the gateway. I have the script set to call on an alarm pipeline and would like notifications when high and critical alarms come up for operators. Is there some way around this? It has been a few years so I wasn't sure if there were any developments that might change the script to play the audio through the clients open. I have tried with a URL and not a local sound file but ran into the same issue. I figured since this comes with a windows install that it would be safe to use across windows machines.
system.util.playSoundClip("file:///C:/Windows/media/tada.wav")

It was never broken. That's the way web-based stuff works. Browser security won't let you access files on the client's computer without user interaction (such as file upload).

See PGriffith's link in post #7 for a workaround.

I saw that with the Iframe, when I tested it with a toggle switch it brought up the audio but it needed to be played by pushing play. Is there a way to get that to run automatically? Can this be triggered without using the Iframe by just using a script so I can call it directly from the alarm pipeline?

Autoplay is disabled by default on browsers nowadays.

Perspective has an audio component you can try...

4 Likes

You are fighting against browser security. Even if you get it to work in one place, with a particular browser, the odds of audio-play requirements changing is high. If you need audible alarms, wire up a sound system to your PLC.

(For light-duty audio, try Vision.)

Using that component eliminates the play issue since that allows it to be bound. I already have a popup that comes up when a new alarm becomes active. I was able to put that object on that one screen and have it deploy across my application. It does seem like there really should be a script I can run from the alarm pipeline instead of needing a crazy work around in the name of security. Is there no better way to do this then a hidden object tucked away?

Don't use browsers for important tasks. :man_shrugging:

1 Like

Except many alarm limits can be changed from ignition. I would need to have a tag in the PLC reading Ignition, which reads the PLC, seems like a lot of steps and extra costs associated when it could be streamlined. This company is trying to rollout Perspective as a standard so Vision is out of the question. If I can make an audio play through the client no matter which screen you are on by manipulating that audio object, I am not sure why it is so much safer and secure than a script with the same capability. How many websites such as news outlets and YouTube that have audio and clips play from a webpage without user interaction? Just seems like something that could improve perspective to have an easy script to call from the alarm pipeline to play an audio when an alarm occurs regardless of what screens you are on.

The browser was just for testing, the site uses Perspective Workstation.

My opinion on this is scattered all over this forum. To summarize: on-machine HMIs that have critical functions can only be implemented reliably in Vision. The company is screwing up.

Ignition's Jython doesn't run in the browser. Full stop.

Carry on as you wish.

2 Likes

Perhaps this could be a feature request for Perspective Workstation (& App) users, via a new system.perspective function? :thinking: