In React audio tag not working, instead it just displays the link

In React I am getting the source file dynamically through an api call. <audio src={rec.data2} type="audio/mp3" controls autoplay /> It is not displaying the usual play button with volume control, instead it just displays the link. What am I doing wrong?

Upvotes: 2

Views: 410

Answers (1)

antoineso
antoineso

Reputation: 2151

try this:

<audio controls>
  <source src={rec.data2} type="audio/mpeg">
</audio>

w3Schools explain it :

Definition and Usage The tag is used to embed sound content in a document, such as music or other audio streams.

The tag contains one or more tags with different audio sources. The browser will choose the first source it supports.

The text between the and tags will only be displayed in browsers that do not support the element.

There are three supported audio formats in HTML: MP3, WAV, and OGG.

Upvotes: 1

Related Questions