The audio element with id="beep" must be 1 second or longer

My 25 +5 clock passed all the tests but one, it said that The audio must be 1 second or longer, I even used the same audio used in FCC example.
link : 25 + 5

It isn’t the audio file, it is how you are using it. You can’t just set the src and rely on autoplay. Here is what I did to make your project pass.

  1. No need for an Audio component, so I just added the audio element to the JSX.

  2. Set the src on the audio element directly, no need for state.

  3. Create a ref in the constructor and set it on the audio element.

this.audioRef = React.createRef();
<audio src="" id="beep" ref={this.audioRef}></audio>
  1. Call play() on the audio element ref as needed (in place of the two src setState you have now).;
  1. Call pause() and reset the currentTime inside your reset method.
this.audioRef.current.currentTime = 0;
1 Like

Thank you, I never worked with a ref, I should give it a look.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.