I want to play a track in my React web app. I follow a video and try everything that is done there, but when I click the button to call a function which should trigger audio.play(), the track isnt played.
Below is the code I have so far.
This is the button with some scss to it:
<div className="audio-player">
<button className="play"><i className="ion-play" onClick={this.playTrack}></i></button>
<div className="seek-bar">
<div className="fill"></div>
<div className="handle"></div>
</div>
</div>
As you can see, the onClick{} should call this function:
playTrack = () => {
let audio = new Audio('song.ogg');
audio.play();
}
But It doesnt play. Now, my guess is that the song I am providing can't be found or binded. I tried the mp3 format also the ogg format.I am storing the track in the folder directory where the src folder is. I converted the mp3 format to an ogg and when I open it from my folder it opens in the browser. But sadly It cant be played in my web app.
So my goal is to hear the song being played when the onClick is triggered.