Playing .wav file via Java Action only works locally

0
We are trying to make a Java action to play a .wav file if it's in the designated folder on the user's PC. Here's the code we have so far: // BEGIN USER CODE String soundLog = ""; switch(SoundTypeParameter1) { case ACCESS_GRANTED: LOG.info("Should play access granted sound"); soundLog += "Should play access granted sound"; soundLog += playSound(new File("C:/sportivity/sounds/access_granted.wav")); break; case ACCESS_DENIED: LOG.info("Should play access denied sound"); soundLog += "Should play access denied sound"; soundLog += playSound(new File("C:/sportivity/sounds/access_denied.wav")); break; default: LOG.info("No SoundType found"); soundLog += "No SoundType found"; } return soundLog; // END USER CODE And here's the playSound function (the string return is purely for logging): // BEGIN EXTRA CODE public static ILogNode LOG = Core.getLogger("RickSoundTest"); public String playSound(File file) { try { Clip clip = AudioSystem.getClip(); clip.addLineListener(new LineListener() { public void update(LineEvent lineEvent) { if (lineEvent.getType() == LineEvent.Type.STOP) clip.close(); } }); clip.open(AudioSystem.getAudioInputStream(file)); clip.start(); LOG.info("Sound has played"); return " - Sound has played"; } catch (Exception ex) { LOG.error("Error in playing sound: " + ex.getMessage()); return " - Error in playing sound: " + ex.getMessage(); } } // END EXTRA CODE   When we run our app locally, everything works fine. When we run the same function in our live environment, we get the following error: No line matching interface Clip supporting format PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian is supported   We're stuck now, Googling this message doesn't lead to reasonable solutions in our case. Does anyone have experience with playing .wav files via a Java action?
asked
2 answers
2

I suspect what the error is trying to tell you, is that the .wav file is not present on the server. Because the Java code you are running is executed on the server, it will never be able to find the file on your local harddrive. If you need your app to play sounds, you should investigate doing it via javascript in the browser.

answered
0

If someone has the same issue, we fixed it by using the Play Audio widget and triggering the Javascript action via a nanoflow.

 

https://marketplace.mendix.com/link/component/120804

answered