chadpaulson / react-cassette-player

Simple ReactJS HTML5 audio player component built with SVG icons from The Noun Project.

Home Page:https://chadpaulson.github.io/react-cassette-player

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Audio element doesn't play new audio when src updated via props

mwilc0x opened this issue · comments

Hey,

Thanks for this project, this is really cool! I noticed this component would not play new audio when new props were passed to src attribute. I was able to fix it by adding:

  componentDidUpdate: function(prevProps, prevState) {
    if(prevProps.src !== this.props.src) {
      var node = this.refs.player.getDOMNode();
      node.src = this.props.src;
      node.play();
    }
  },

It's kind of hard to test for this. If you inspect element after passing new props to src the new props are there but the new audio does not play. It wasn't until I manually grabbed the node via getDOMNode, placed src on it and called .play() did it play new audio right away.

Lemme know... I'll gladly send a PR if you'd like to add this.

Hi Mike,

Thanks for taking the time to look at the project. This issue is certainly reasonable and I appreciate your contribution. Feel free to send a pull request, just be sure to include a check of the mimeType property as well. I would love to learn more about your implementation.

Hi Mike,

I hope this solves your issue. Thanks again for taking the time to contribute to the project.

Best,
Chad

Hey Chad,

Sorry for the late response. I just tested your latest version and it is indeed working when passing in new props. I appreciate you taking the time to fix. Nice job again on this sweet component! 🎵 🎵 🎵

Cheers,
Mike