playcanvas / playcanvas/engine
Sound Event Play not firing after first user interaction
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 16.8k
- Forks
- 2k
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 222
Description
Hey Playcanvas Team,
love your work!!! ❤️
Carrying this over from https://forum.playcanvas.com/t/sound-event-listener-on-play-not-working/12827
Setting a sound component Autoplay to TRUE will not trigger the onPlayEvent when the user interacts for the first time. The onResumeEvent will also not work.
Demo:
https://playcanvas.com/project/680856
var soundOrigin = this.app.root.findByName('SoundOrigin').sound;
console.log("hasevent"+soundOrigin.hasEvent("play")); //<-- false
soundOrigin.on("play", function (a, b) {
console.log("Sound started");
});
The Soundboggs-Entity has the sound emitter.
The Avatar has a visualizer script which trys to register the play event.
Once you click into the scene the sound starts but the Event never fires.
If you set the Soundboggs-Sound to autoplay=false and activate the onMousedown function in the visualizer script you get the working solution.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the sound component's autoplay and event handling, using the linked demo and the visualizer script's registration of the play and resume events as the reproduction path. Compare this with the working onMousedown path after autoplay is disabled. Done means the play event fires when autoplayed sound begins after the first user interaction, and the resume event behaves consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- audio-video-rtc, game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100