JavaScript HTML: Multiple onclick Audio files, make the last one stop html multiple onclick actions,html multiple onclick functions,html multiple

I visit this site all the time to search for solutions, but I couldn't find an answer to my question.

I want to add multiple audio files to a page. So I used the following coding. What this does is when you click one file, it starts playing the music, when you click the next file the rest will pause. That's what I wanted.

But I also want the play/pause option on each file; so when you click the "listen/pause" link for "Night Swim", it starts playing, and when you click the same link again, it will stop.

Is there any way I can do this? I'm not very handy with Javascript, I tried all sorts of other codes but nothing seems to work the way I want it.

I hope someone can help me and I hope my problem is explained correctly (I'm Dutch, I apologize for my English :S )

Here's my code:

<audio id="1"> 
<source src="everynight-snippet.mp3" type='audio/mpeg'>
</audio>
<audio id="2"> 
<source src="nightswim-snippet.mp3" type='audio/mpeg'>
</audio>

Every Night (<a target='_blank' href="#" onclick="aud_play_pause('1')">Listen/Pause</a>)
Night Swim (<a target='_blank' href="#" onclick="aud_play_pause('2')">Listen/Pause</a>)

And the script:

<script>
ids = new Array(2); // an array with total number of ids
function aud_play_pause(idNumber) {
var idNumber = document.getElementById(idNumber);

for(var i=0; i<ids.length; i++){
document.getElementById(i+1).pause(); // Pause all ids before playing next file.
document.getElementById(i+1).currentTime = 0; // Set the time back to zero, else it will replay from the pause point.
}

idNumber.play();
}
</script>

So to sum it up:

  • If I click the first song (Every Night), it starts playing. When I click it again, it should stop playing.
  • If I click the second song (Night Swim) while the first one plays, the first song should stop playing and the second song should start. If I click the second song again, it should stop.
  • etc
Answer:1

In a Google sheet, I have a custom form based off of some posts/blogs that I have found online to learn more about Google App Scripts. The form works correctly but I am having trouble with the column ...

In a Google sheet, I have a custom form based off of some posts/blogs that I have found online to learn more about Google App Scripts. The form works correctly but I am having trouble with the column ...

  1. inputting into array java
  2. inputting data into array java
  3. inputting elements into an array in python

Im using ReactJS with React-Router for a dashboard style application. App.js <div> <Toolbar/> <RouteHandler lang={this.state.lang} account={this.state.account} logout={this....

Im using ReactJS with React-Router for a dashboard style application. App.js <div> <Toolbar/> <RouteHandler lang={this.state.lang} account={this.state.account} logout={this....

I am creating a function that takes in an array of unsorted integers and returns an array of the unique integers, sorted by frequency. However, if the integers have the same frequency, they will be ...

I am creating a function that takes in an array of unsorted integers and returns an array of the unique integers, sorted by frequency. However, if the integers have the same frequency, they will be ...

I want to sort an array based on an sort order. public array1: Array<string> = []; array.push(some string values); //E.g dog,apple,man I have a sort order like dog = 1 apple = 3 man = 2 So ...

I want to sort an array based on an sort order. public array1: Array<string> = []; array.push(some string values); //E.g dog,apple,man I have a sort order like dog = 1 apple = 3 man = 2 So ...

  1. typescript array sorting
  2. typescript array sorting string
  3. typescript array sort by property
  4. typescript array sort by date
  5. typescript array sort alphabetically
  6. typescript array sort descending
  7. typescript array sort compare function
  8. typescript array sort example
  9. typescript array sort function
  10. typescript array sort multiple fields
  11. typescript array sort ascending
  12. typescript array sort by key
  13. typescript array sort not working
  14. typescript array sort objects
  15. typescript array sort by number
  16. typescript array sort by value
  17. typescript array sort desc
  18. typescript array sort by field
  19. typescript array sort by name
  20. typescript array sort lambda