Without any input the SoundComponents often don’t start even if AutoPlay is activated. I would like to track when the sound starts. Looking up an Entity and accessing the Sound Element seems to work but the on-Play event never fires…
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');
});
SoundOrigin is an entity with a Sound and track component. I think I have a logic error…
I am aware of this restriction and actually I really welcome it. I hate autoplay sound on sites! Using chrome here. The problem is not the sound not playing directly. But when the sound plays (because of an interaction) I want to know. Thats what the listener on the event is for but it will not connect.
In real life a user interaction would have already occured rendering this particular problem obsolete.
But having an event working would be desirable. I would not like to hack this via script-click and I dont even know if this would work.
I worked on creating a simple testcase for you to look at and realised a couple of things:
Even if Autoplay is turned to FALSE the browser (chrome) throws a warning because of the created AudioContext. This is okay but confused me - my fault.
Setting Autoplay to TRUE will not trigger the onPlayEvent when the user interacts for the first time. The onResumeEvent will also not work.
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.
Guys, this is kinda a fringe case and it doesn’t cause me any problems. The event works everytime after the first user interaction. You can flag it solved. I would like to know if you consider this a bug or standard behavior or ‘this is just the way the web works’. Just out of curiosity.