The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

2 Pages V < 1 2  
Reply to this topicStart new topic
> How to play an audio track without using "controls"
fspade
post Jan 24 2022, 09:32 AM
Post #21





Group: Members
Posts: 8
Joined: 22-January 22
Member No.: 28,234



QUOTE(Christian J @ Jan 24 2022, 02:58 PM) *
Each AUDIO element needs its own unique ID value. Also, each corresponding link needs to send that same value as its function call parameter, ...
Then it automatically translates into the "audio_id" argument in the function:
That makes a lot of sense. I'll test it later, but have no doubt.

Thanks Christian, I am happy about you all's help.

PS: I owe you at least a coffee.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
fspade
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jan 24 2022, 09:57 AM
Post #23


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



We aim to please. biggrin.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 24 2022, 04:33 PM
Post #24


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Jan 24 2022, 03:14 PM) *

QUOTE(Christian J @ Jan 24 2022, 02:58 PM) *

(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. biggrin.gif

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? unsure.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jan 25 2022, 06:06 AM
Post #25


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
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. unsure.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Jan 25 2022, 11:26 PM
Post #26


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE(pandy @ Jan 25 2022, 08:06 PM) *

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. unsure.gif


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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 26 2022, 10:33 AM
Post #27


.
********

Group: WDG Moderators
Posts: 9,630
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. wacko.gif

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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jan 26 2022, 04:01 PM
Post #28


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Maybe the OP's files are only short snips. tongue.gif

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. biggrin.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 26 2022, 05:26 PM
Post #29


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Jan 26 2022, 10:01 PM) *

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. biggrin.gif

I often use "Toggle" in such cases. cool.gif

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';
    }
}
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jan 26 2022, 06:06 PM
Post #30


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
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. biggrin.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 26 2022, 08:15 PM
Post #31


.
********

Group: WDG Moderators
Posts: 9,630
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. laugh.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jan 26 2022, 11:03 PM
Post #32


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

2 Pages V < 1 2
Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 05:21 AM