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. |
Christian J |
Jan 26 2022, 10:33 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,665 Joined: 10-August 06 Member No.: 7 |
Thought I'd try to improve the player. In this version you only need one AUDIO element. While testing with my own audio files I also realized the need for a stop button.
CODE <script type="text/javascript"> function playIt(task) { var audio=document.getElementById('myAudio'); if(task=='stop') { audio.pause(); } else { audio.src=task; audio.play(); } } </script> <audio id="myAudio"></audio> <a href="dasende1.mp3" onclick="playIt(this.href); return false;">Vorlesen1...</a> <a href="dasende1.mp3" onclick="playIt(this.href); return false;">Vorlesen2...</a> <a href="#" onclick="playIt('stop'); return false;">Stop audio player</a> |
pandy |
Jan 26 2022, 04:01 PM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,734 Joined: 9-August 06 Member No.: 6 |
Maybe the OP's files are only short snips.
I haven't googled, but there ought to be a way to check if the audio is already playing and if it is the same link could be used to both start and pause it. The script would also have to change the link text from Play to stop though. "Play or Stop" is just too odd. |
Lo-Fi Version | Time is now: 13th May 2024 - 11:28 AM |