HTML5 tag in React

I want to use a simple HTML5 tag in my react app. My component looks like this:

import React from 'react'

class AudioPlayer extends React.Component {
  render() {
    return (
      <div>
        <audio ref="audio_tag" src="./static/music/foo.mp3" controls autoPlay/>
      </div>
    );
  }
}

export default AudioPlayer;

      

but he just won't play. I also have no errors. I put the mp3 file in every separate folder in my application and tried different paths etc. but it doesn't seem to recognize it. Maybe I missed something trivial?

+3


source to share


1 answer


I accidentally used a broken audio file, so this explains why my solution doesn't "work". The code above, as Jordan Running points out, is great, so I'll leave that as an answer.



0


source







All Articles