title: Detecting WebAudio sound end
body: <p>I'm using a javascript build a radio and I'm trying to give it different functionalities but I need to be able to detect the end of a song to make it work. Is there any way to do this?</p>
  
  <p>I've tried different methods I've found online like .ended and such but I don't think those work without using the html audio tag. So I tried to make an audio tag that uses the same data for the source that my js radio uses and get the file length to stop my sourceNode at the end time and make a new one but but i keep getting null returned as the data so that doesn't work either.</p>
  
  <p>I want to do something like:</p>
  
  <pre><code> context.onended = function() {
      $.ajax({
          url: '../scripts/radio.php',
          data: {
            attr1: 'value1'
          },
          success: function(data) {
          console.log(data);
  
          fileChosen = true;
          setupAudioNodes();
  
          var request = new XMLHttpRequest();
  
          request.addEventListener("progress", updateProgress);
          request.addEventListener("load", transferComplete);
          request.addEventListener("error", transferFailed);
          request.addEventListener("abort", transferCanceled);
  
          request.open('GET', data, true);
          request.responseType = 'arraybuffer';
  
          // When loaded decode the data
          request.onload = function() {
  
              $("#title").html("Title");
              $("#album").html("Goes");
              $("#artist").html("Here");
              onWindowResize();
              $("#title, #artist, #album").css("visibility", "visible");
  
              // decode the data
              context.decodeAudioData(request.response, function(buffer) {
              // when the audio is decoded play the sound
              sourceNode.buffer = buffer;
              sourceNode.start(0);
  
              $("#freq, body").addClass("animateHue");
              //on error
              }, function(e) {
                  console.log(e);
              });
          };
          request.send();
  
      }
      });
  </code></pre>
  
  <p>I want for this to run at the end of a song and play the next file. Which it would work if I could get the end time of the currently playing song.</p>