Page 1 of 2

Play a sound file from Rich Display File App

Posted: Wed Mar 15, 2017 11:57 am
by riback9
I bet Scott Clement can answer this...

How do we play a sound (.wav) or something when an event occurs?

Example (amount > limit) "BUZZZZZZZZ"

The last topic for .wav was back in 2011 (Brian May). We hope newer versions may have been enhanced.

Thanks

Re: Play a sound file from Rich Display File App

Posted: Wed Mar 15, 2017 4:45 pm
by Scott Klement
https://www.w3schools.com/jsref/met_audio_play.asp

Is there something more specialized about this that you need to know, or...?

Re: Play a sound file from Rich Display File App

Posted: Fri Mar 17, 2017 12:03 pm
by riback9
Sorry about mis-spelling your name... I must be distracted...

Can we play a .wav file in windows from an RPGLE program? If so, any examples available?

Thank you very much Scott Klement !

Re: Play a sound file from Rich Display File App

Posted: Fri Mar 17, 2017 1:22 pm
by riback9
Scott, I just realized that we already use the js functions() in the default IFS dir "custom"
So I guess we would put another function from the link you sent - triggered by an event ("On Change") or something.
I do have a .js file named for a specific application program that retains column filters, can I just add another .js file and will ProfoundUI search ALL the .js files in custom for a function? Should I not name the .js file for the application and call it something else since I do not refer to the .js file on the event call "myonsubmit()" ... Thanks

Re: Play a sound file from Rich Display File App

Posted: Fri Mar 17, 2017 3:27 pm
by Glenn
If you are running a Rich Display session (using the /start URL) then, yes, Profound UI will load anything you put in /custom. If you are running a Genie session you will need to add an additional <script> tag to the start.html file of your skin if you create a new .js file in custom.

How you name the .js files in the /custom directory depends on how you want to group things. Some customers might create one file with everything in it or break them into different files based on some shop standard.

Glenn

Re: Play a sound file from Rich Display File App

Posted: Fri Mar 17, 2017 4:26 pm
by Scott Klement
I'm not sure that I understand how the .js files in userdata/custom are related. Are you saying that you'll put the JS code to play a wav file into a function, and then call it when you need it?

You can do that -- but it is only one or two lines of code, so it seems like it's not necessary to do that?

For example, you could simply put this in any JavaScript event (onload, onchange, onclick, etc):

Code: Select all

var sound = new Audio('/tada.wav');
sound.play();
Replace "/tada.wav" with the URL to any wave file you want to play.

Or, if you wanted it to be a one-liner, you could do this (I think it's a bit harder to read, but it's up to you):

Code: Select all

new Audio('/tada.wav').play();
If you only want to do it based on a condition in your RPG program, of course, you could set a hidden field in your display file, and check that field from JavaScript. So maybe you'd create a hidden textbox with id=PLAYDATA, bound to RPG variable PLAYTADA. The RPG variable could put 'Y' into the field, then do EXFMT to show your screen. The onload of the screen could do this:

Code: Select all

if (get("PLAYTADA") == "Y") {
   new Audio("/tada.wav").play();
}
I hope you're getting the idea! Really, none of this is related to Profound UI -- it is just 'regular' web programming that will work in any web page, whether it's Profound UI or not... You can Google it and find hundreds, even thousands, of pages telling you how to do it. I linked one of them in my previous message.

To me, this is a very simple example of why it's powerful that Profound UI is based on mainstream technologies like HTML5. There doesn't need to be any features in Profound UI for this because you can take advantage of all of the built-in capabilities of the web browser.

Re: Play a sound file from Rich Display File App

Posted: Mon Mar 20, 2017 9:49 am
by riback9
Thank you very much Scott, once again. The information is very helpful to us. We are close to retirement so you know the saying about old dogs...
(we cheat).
:)

Re: Play a sound file from Rich Display File App

Posted: Mon Mar 20, 2017 3:56 pm
by smohsen
I tried the following code in onclick event of a button named 'Play1'.
var sound = new Audio('\\172.16.1.1\TEST\TADA.WAV');
sound.play();

"\\172.16.1.1\TEST\TADA.WAV" is my URL of the wave file. When I click the button 'Play1' nothing happens.
I must not be doing it right.

Re: Play a sound file from Rich Display File App

Posted: Tue Mar 21, 2017 9:38 am
by Glenn
The web server will only allow the browser to access files in the document root (usually /www/<instance name>/htdocs). You will need to put the TADA.WAV file somewhere in that directory. You will then want to use only the path relative to the document root in the Audio() object.

For example, if you create a directory named 'test' in /www/<instance name>/htdocs you would make the first line to look like this...
var sound = new Audio('/test/tada.wav');

Glenn

Re: Play a sound file from Rich Display File App

Posted: Tue Mar 21, 2017 2:17 pm
by Scott Klement
What you've coded looks like a Windows UNC path. You need to provide a valid HTTP URL (relative or absolute).

So something like http://www.example.com/xxx/yyy.wav or just /xxx/yyy.wav (where it will use the same server as your display.)

Assuming you are serving the file from your IBM i, then it would indeed be within your document root as Glenn points out (unless you configure your HTTP server differently).