darkdefender
darkdefender

Reputation: 151

Audio Tag not working with React.js

I am developing a single page react application using "Create React App" on my system. I am trying to incorporate an Audio tag, which is rendered, but only the "play" button is seen which is disabled, and the rest of the controls are not seen. Can anyone please point me where I might be wrong?(I tried the same code on WAMP server where it works fine)(And I am using chrome as my browser)

<audio controls id="beep" >
              
              <source src="./mysound.mp3" type="audio/mp3" />
               Your browser does not support the audio tag.
</audio>

Upvotes: 5

Views: 6299

Answers (1)

darkdefender
darkdefender

Reputation: 151

Okay, I figured it out and it turned out to be pretty simple in the end(silly of me in the first place). I needed to do 2 things:-

  1. Add "import sound from './mysound.mp3' " at the top of my react code.

  2. Change "src='./mysound.mp3" to "src={sound}"

Thank you to those who responded. Your responses pushed me in the right direction. :)

Upvotes: 9

Related Questions