play sounds in HTML5

hh hh at hyperhh.de
Sat May 25 07:26:02 EDT 2019


To avoid misunderstandings:
This relates to a HTML5 standalone, not to using HTML5 in a browser widget.

We could use two steps.

Step 1.
Use one certain audio file. Make this work from the html file containing

<audio id="myAudio">
  <source src="./audio/piano-melody.wav" type="audio/wav">
</audio>

where audio is a folder at the same location as your html file
(on the server that is running your standalone. Files from other urls
(CORS) may be not available due to SOP/ user's browser behaviour).

Step 2.
You already wrote that step 1 works for you as above (or in a similar way)
with a certain audio file.
You ask now how to play available sounds (which may vary) in random order.

For that you can sort the available filenames in LC by random.

Then set one after the other as the one you play/pause with your buttons.
Using the identifiers from the tutorial this setting can be done as
follows in a HTML5 standalone.

-- assume "guitar-melody.wav" is the randomly chosen filename
-- or the next/previous filename in a fixed order

put "./audio/guitar-melody.wav" into myFile
put "document.getElementById('myAudio').src=" into tScript
do tScript & "'" & myFile & "'" as "JavaScript"

Then use your buttons play/pause as usual.

[If questions remain you could also post in the HTML5 subforum where
you can add attachments.]




More information about the Use-livecode mailing list