Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
A-frame sound : How to react to the end of the sound?

Loop false, poolsize 1.

Running sound.playSound() successfully plays the sound, but sound.isPlaying remains true even after the full sound has been played.

Already tried adding the 'sound-ended' event listener on the entity but it doesn't trigger neither.

There must be a proper state somewhere... right ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can track the state of the sound component by listening to the sound-ended event. Below, click the button to play a sound, it will remain red until the audio track is over.

<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script>
  AFRAME.registerComponent("foo", {
    init: function() {
      const soundComp = this.el.components.sound; // grab the `sound` component
       
      // play the sound when the user clicks the button
      this.el.addEventListener("click", evt => {               
        this.el.setAttribute("color", "red") // turn the button red
        soundComp.playSound(); // playsound
      })

      // catch the `sound-ended` event
      this.el.addEventListener("sound-ended", evt => {
        this.el.setAttribute("color", "green") // turn it back to green
      })
    }
  })
</script>
<a-scene cursor="rayOrigin: mouse" raycaster="objects: a-sphere">
  <a-assets>
    <audio id="ding" crossorigin="anonymous" src="https://gftruj.github.io/webzamples/arjs/sound/sound/Ding-sound-effect.mp3" preload="auto"></audio>
  </a-assets>
  <a-sphere position="0 1 -3" radius="0.25" color="green" sound="src: #ding; autoplay: false" foo ></a-sphere>
</a-scene>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!