Audio loop setting?

Here’s an idea I found

audioElement.setAttribute('onended', 'window.location.reload()');

This is for refreshing the page of course, but maybe we could make it to just refresh/reload the audio after it ends :thinking:

Here’s the full code

window.onload = function() {

var clear = document.getElementById("clear");
var audioElement = document.createElement('audio');
    audioElement.setAttribute('src', 'paper_crumple.mp3');
    audioElement.setAttribute('preload', 'auto');
    audioElement.setAttribute('onended', 'window.location.reload()');

function playAudio() {
    audioElement.load;
    audioElement.play();
};

clear.onclick = function() {
    localStorage.clear();
    playAudio();
    $("#wrapper").addClass("fadeOutDown");
};

};

On that web page I have not found any of the script you posted in your opening post to this topic (post #1).

I understand. Yeah everyday I open it, it shows blank, so I have to add the js in there again. I don’t know why it’s like this now. It was fine before.

I now see it’s in audioplayer.js file

1 Like

Yes, but it won’t stay in there tomorrow lol I would have to put it there again.

Thinking maybe we should add this?

onended = (event) => {};

Tried this one but didn’t work

clearInterval(updateTimer);

resetValues();

File audioplayer.js currently includes this JavaScript:

audio.addEventListener('progress', displayBufferedAmount);
      seekSlider.addEventListener('input', (e) => {
        showRangeProgress(e.target);
        currentTimeContainer.textContent = calculateTime(seekSlider.value);
        if (!audio.paused) {
          cancelAnimationFrame(raf);
        }
      });

You need to insert this just before the above JavaScript:

audio.addEventListener("ended", () => {
  playIconContainer.click();
  cancelAnimationFrame(raf);
  currentTimeContainer.textContent = "0.00";
  seekSlider.value = "0";
});

(It coud be inserted in some other places, but it makes sense to insert if just before the existing listener code for “progress”).

1 Like

It’s already before that

image

What if we put the two together?

Scratch that, I don’t think the above idea will work. How about with this…

audio.addEventListener("ended", function(){ switchTrack(); });

we could try instead of switchTrack, do something like restartTrack, or reloadTrack

Idk, I’m just trying out many things here, but really want to related to the code that we already have.

Your audioplayer.js file is here. It does not currently include the ‘ended’ event listener.

1 Like

How can I access that to add it?

Maybe if I copy the JS I have from the website that has it, I can then save it again as .js file, and get another static link like I had before…dunno…

Ok I replaced it with the one that has the ended event listener… let me know if you can see it.

It’s working!

1 Like

Yeeeeeeahhhh!!! :smiley:

Ok, it plays here, but the 0:00 is not updating, nor is the slider moving. Do I need to refresh page a few times? A hard refresh?

Maybe not cause that didn’t help.

Did the slider go forth and 0:00 change when you played the audio again?