ncaught (in promise) DOMException: The element has no supported sources while trying to play audio in React.js

Viewed 78

This is the code I have tried, I can't figure out what is going wrong here, but when I try to call the "changePlayingStatus" function on a click event, the error is raised.

const [playing, togglePlaying] = useState(false);
const [audio] = useState(new Audio("bg_music.mp3"));

  const changePlayingStatus = () => {
    playing ? audio.pause() : audio.play();

  togglePlaying(!playing);
}
0 Answers
Related