How to play an audio track without using "controls" |
How to play an audio track without using "controls" |
fspade |
Jan 24 2022, 09:32 AM
Post
#21
|
Group: Members Posts: 8 Joined: 22-January 22 Member No.: 28,234 |
Each AUDIO element needs its own unique ID value. Also, each corresponding link needs to send that same value as its function call parameter, ... That makes a lot of sense. I'll test it later, but have no doubt.Then it automatically translates into the "audio_id" argument in the function: Thanks Christian, I am happy about you all's help. PS: I owe you at least a coffee. |
fspade |
Jan 24 2022, 09:46 AM
Post
#22
|
Group: Members Posts: 8 Joined: 22-January 22 Member No.: 28,234 |
It works! I love it.
|
pandy |
Jan 24 2022, 09:57 AM
Post
#23
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
We aim to please.
|
Christian J |
Jan 24 2022, 04:33 PM
Post
#24
|
. Group: WDG Moderators Posts: 9,658 Joined: 10-August 06 Member No.: 7 |
(Hope I got the terminology right there, I always mix up parameters and arguments.) I've never known what that's called and I've even searched for it. Now I at least know it's either argument or parameter. Probably. Here they use both on the same page: https://developer.mozilla.org/en-US/docs/We...Function/length "length is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters." Maybe an argument is a kind of parameter? |
pandy |
Jan 25 2022, 06:06 AM
Post
#25
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
Maybe argument and parameter are the same thing. I find these and similar definitions.
An argument is a way for you to provide more information to a function. A parameter is a special kind of variable used in a function to refer to one of the pieces of data provided as input to the function. Argument is the term I'm more used too, feels more "programmy". For some reason I haven't thought of this as an argument, but I suppose it is. |
Brian Chandler |
Jan 25 2022, 11:26 PM
Post
#26
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
Maybe argument and parameter are the same thing. I find these and similar definitions. An argument is a way for you to provide more information to a function. A parameter is a special kind of variable used in a function to refer to one of the pieces of data provided as input to the function. Argument is the term I'm more used too, feels more "programmy". For some reason I haven't thought of this as an argument, but I suppose it is. I wouldn't give either of these definitions more than 1/10. Basically there is very little difference in meaning between "argument" and "parameter", but I think normally in mathematics a function has arguments; if anything "parameter" is more "programmy", because it is more likely to be used for subroutines (remember them?) More generally parameter has a meaning relating to generalisation. If you have a bunch of functions (or for that matter, web pages) each of which retrieves the information about puzzles from a particular manufacturer's website, then you might decide to integrate these into a single function or page, parameterised by manufacturer. |
Christian J |
Jan 26 2022, 10:33 AM
Post
#27
|
. Group: WDG Moderators Posts: 9,658 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
#28
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 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. |
Christian J |
Jan 26 2022, 05:26 PM
Post
#29
|
. Group: WDG Moderators Posts: 9,658 Joined: 10-August 06 Member No.: 7 |
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. When I clicked again my audio just restarts. There's a CONTROLS attribute you can use, which is perhaps better since it gives the user a standardized interface, but maybe it will be confusing together with the above javascripts (without the scripts you may have to use separate AUDIO elements for each file). QUOTE The script would also have to change the link text from Play to stop though. "Play or Stop" is just too odd. I often use "Toggle" in such cases. CODE var state; function playIt(url) { var audio=document.getElementById('myAudio'); if(audio.src==url && state=='playing') // same file is already playing { audio.pause(); state='paused'; } else { audio.src=url; audio.play(); state='playing'; } } |
pandy |
Jan 26 2022, 06:06 PM
Post
#30
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
OK, state it is. I was almost sure there was something like that, but didn't want to search for it.
|
Christian J |
Jan 26 2022, 08:15 PM
Post
#31
|
. Group: WDG Moderators Posts: 9,658 Joined: 10-August 06 Member No.: 7 |
Now you confused me, did you mean "toggle"?
I can make the script change the link text when it's clicked if I have to. |
pandy |
Jan 26 2022, 11:03 PM
Post
#32
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
Sorry, I just skimmed and didn't see state was a variable you created. I mistook it for an audio property. I see now when you did.
|
Lo-Fi Version | Time is now: 26th April 2024 - 02:40 PM |