Task: play several audio files one after another. There were several attempts to do this through Audio and through the collection of samples in AudioContext, but my knowledge was not enough. ._.

Naturally, when you call audio.play () several times in a row, these files are played simultaneously and that's all.

Tell me, what can I do or where to read about it?

  • Do you need to play all the audio in turn? - Yuri
  • @Yuri, yes, you can say that. - Abnormally

1 answer 1

To flip through audio recordings, write all the audio into an array and scroll with onended :

 var songs = [ 'http://zf.fm/download/4824354', 'http://zf.fm/download/3860794', 'http://zf.fm/download/2962900' ]; window.onload = function() { var audio = document.querySelector('audio'); audio.song = 0; audio.src = songs[audio.song]; audio.onended = function(e) { if(this.song == songs.length - 1){ this.song = 0; }else{ this.song++; }; this.src = songs[this.song]; this.play(); }; }; 
 <audio controls=""> 

  • Huge huge thanks! :) - Abnormally
  • one
    @NetScum, and for general development: this can be done without adding an audio element to html - Yuri
  • This is me in the course (var sound = new Audio ('src / snd / 3.1.wav') for example, yes?). I actually do that. I have separate buttons for playing sounds. The problem was precisely that I did not understand how to organize the output of sounds one after another (not always, but sometimes this is required). Recently I started working closely with JS and much is still not clear. Thanks again. : 3 - Abnormally
  • one
    @NetScum, you can, in principle, either, or through document.creatElement('audio') - Yuri
  • one
    @NetScum, yes. At the same time DOM Audio will be stored in JS - Yuri