vendredi 6 mars 2020

Testing audio in react

I have music player application in react and I want test when a music finished, next music play automatically. E.g. I have a music with 5 seconds duration and I click play button and after 5 seconds next music on list must play. How can I do this? Here is my code:

this.audio.addEventListener("ended", () => {
  Musics.length - 1 === this.state.currentMusic
  ? this.setState({
      isPlaying: false,
      currentMusic: 0
    })
  : this.setState({
      currentMusic: this.state.currentMusic + 1
    });
});

Aucun commentaire:

Enregistrer un commentaire