playcanvas / playcanvas/engine

Sound Event Play not firing after first user interaction

Open
#2,017 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: sound
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.