How to play an audio track without using "controls" |
How to play an audio track without using "controls" |
giomach |
Jun 19 2021, 12:07 PM
Post
#1
|
Group: Members Posts: 2 Joined: 19-June 21 Member No.: 27,985 |
I have an audio file (mp3), and I want to allow the web user to choose to play a section (track) of it.
I could split the audio file into many separate files, but I have begun to look at the <track> sub-element of the <audio> element of HTML5. Many webpages tell us how to formulate this element, eg. to give the start time of each track in a .vtt file, and that is fine. But I don't want "controls", I want to display a list of tracks, and let the user decide which track to play, and click an icon to play it. It must be blindingly obvious how to do this, but I can't find the HTML statement to start up a numbered track. Thanks for any hints. |
fspade |
Jan 24 2022, 07:25 AM
Post
#2
|
Group: Members Posts: 8 Joined: 22-January 22 Member No.: 28,234 |
Sorry, I didn't mean tracks like you do now; I meant individuel mp3 files.
|
Christian J |
Jan 24 2022, 08:58 AM
Post
#3
|
. Group: WDG Moderators Posts: 9,671 Joined: 10-August 06 Member No.: 7 |
Sorry, I didn't mean tracks like you do now; I meant individuel mp3 files. Here's a modification of pandy's script: CODE <script type="text/javascript"> function playIt(audio_id) { var sound = document.getElementById(audio_id); sound.play(); } </script> <audio id="myAudio1" src="dasende1.mp3"></audio> <audio id="myAudio2" src="dasende2.mp3"></audio> <a href="dasende1.mp3" onclick="playIt('myAudio1');return false">Vorlesen1...</a> <a href="dasende2.mp3" onclick="playIt('myAudio2');return false">Vorlesen2...</a> Each AUDIO element needs its own unique ID value. Also, each corresponding link needs to send that same value as its function call parameter, like this: CODE playIt('myAudio1') Then it automatically translates into the "audio_id" argument in the function: CODE function playIt(audio_id) (Hope I got the terminology right there, I always mix up parameters and arguments.) |
Lo-Fi Version | Time is now: 23rd May 2024 - 03:39 PM |