title: HTML5 audio is not playing in my React app in localhost
body: <p>I'm making an mp3 player with React.js and the HTML5 web audio javascript API. I've just been learning React for two weeks so I'm just getting used to the structure and setup (with components etc) however have several years experience with JavaScript.</p>
  
  <p>I had the mp3 player working when using React within the browser. I.e. I had an index.html file and I included the React scripts as follows:</p>
  
  <pre><code>&lt;script src="js/react.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/react-dom.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/browser.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Now I would like to get used to building a React app using the command line and localhost so I started to rewrite the code for use within this environment.
  I started off by creating the skeleton app as follows:</p>
  
  <pre><code>create-react-app my-app
  cd my-app/
  npm start
  </code></pre>
  
  <p>Then I added in my own components etc.
  The application is displaying properly on localhost:3000 however the audio files do not seem to be playing in this environment. I'm unsure if the problem is directly related to the HTML5 audio just not working in localhost or if it's something else.
  There are no errors being returned.</p>
  
  <p>I've simplified my code and also hard-coded in the directory of the mp3 file to the audio tag (see AudioPlayer component) for the moment in order to see if I can get the audio element working.</p>
  
  <p>Can you see anything I might be missing? Thanks</p>
  
  <h1>App Component</h1>
  
  <pre><code>    import React, { Component } from 'react';
      import Header from './Header';
  
      import AudioPlayer from './AudioPlayer';
  
      import Controls from './Controls';
  
      import './music-player.css';
      import './css/font-awesome.css';
  
  
      class App extends Component {
  
           //This class is the main component of the application.
           //it contains the header, the audio player and the side panel components.
           constructor(props) {
                  super(props);
                  this.state = {
                  sidePanelIsOpen: false,
                  currentSoundIndex: 0,
                  isPlaying: false,
                  playerDuration: 0,
                  currentTime: "0:00",
                  currentWidthOfTimerBar: 0,
                  backButtonIsDisabled: false,
                  forwardButtonIsDisabled: false,
                  playButtonIsDisabled: false
  
  
              };
              this.toggleSidePanel = this.toggleSidePanel.bind(this);
  
          }   
          componentDidMount() {
              this.player = document.getElementById('audio_player');
              this.player.load();
              this.player.play(); //this is not doing anything
          }   
          toggleSidePanel(){
              var sidePanelIsOpen = this.state.sidePanelIsOpen;
              this.setState({sidePanelIsOpen: !sidePanelIsOpen})
          }
  
  
          render() {
  
  
              return(&lt;div&gt;
                  &lt;div id="main-container" className={this.state.sidePanelIsOpen === true ? 'swipe-left' : ''}&gt;
                  &lt;div className="overlay"&gt;
  
                  &lt;AudioPlayer sounds={this.props.sounds} currentSoundIndex={this.state.currentSoundIndex} /&gt;
                  &lt;/div&gt;  
                  &lt;/div&gt;
  
  
                  &lt;div id="side-panel-area" className="scrollable"&gt;       
                      &lt;div className="side-panel-container"&gt;
                      &lt;div className="side-panel-header"&gt;&lt;p&gt;Menu&lt;/p&gt;&lt;/div&gt;
  
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;/div&gt;
              );  
          }
  
      }
  
      export default App;
  </code></pre>
  
  <h1>AudioPlayer Component</h1>
  
  <pre><code>    import React, { Component } from 'react';
      import './music-player.css';
  
      const AudioPlayer = function(props) {
          var mp3Src = props.sounds[props.currentSoundIndex].mp3;
          console.log(mp3Src); //this is returning the correct mp3 value
              return (&lt;audio id="audio_player"&gt;
              &lt;source id="src_mp3" type="audio/mp3" src="sounds/0010_beat_egyptian.mp3" /&gt;
              &lt;source id="src_ogg" type="audio/ogg" src=""/&gt;
              &lt;object id="audio_object" type="audio/x-mpeg" width="200px" height="45px" data={mp3Src}&gt;
                  &lt;param id="param_src" name="src" value={mp3Src} /&gt;
                  &lt;param id="param_src" name="src" value={mp3Src} /&gt;
                  &lt;param name="autoplay" value="false" /&gt;
                  &lt;param name="autostart" value="false" /&gt;
              &lt;/object&gt;
              &lt;/audio&gt;    
              );
  
      }
  
      export default AudioPlayer;
  </code></pre>
  
  <h1>index.js</h1>
  
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  import App from './App';
  import registerServiceWorker from './registerServiceWorker';
  import './music-player.css';
  
  var sounds = [{"title" : "Egyptian Beat", "artist" : "Sarah Monks", "length": 16, "mp3" : "sounds/0010_beat_egyptian.mp3"}, 
          {"title" : "Euphoric Beat", "artist" : "Sarah Monks", "length": 31, "mp3" : "sounds/0011_beat_euphoric.mp3"},
          {"title" : "Latin Beat", "artist" : "Sarah Monks", "length": 59, "mp3" : "sounds/0014_beat_latin.mp3"}, 
          {"title" : "Pop Beat", "artist" : "Sarah Monks", "length": 24, "mp3" : "sounds/0015_beat_pop.mp3"},
          {"title" : "Falling Cute", "artist" : "Sarah Monks", "length": 3, "mp3" : "sounds/0027_falling_cute.mp3"}, 
          {"title" : "Feather", "artist" : "Sarah Monks", "length": 6, "mp3" : "sounds/0028_feather.mp3"},
          {"title" : "Lose Cute", "artist" : "Sarah Monks", "length": 3, "mp3" : "sounds/0036_lose_cute.mp3"}, 
          {"title" : "Pium", "artist" : "Sarah Monks", "length": 3, "mp3" : "sounds/0039_pium.mp3"}];
  
  ReactDOM.render(&lt;App sounds={sounds} /&gt;, document.getElementById('root'));
  
  registerServiceWorker();
  </code></pre>