I'm having trouble playing a sound only once when a marker is detected using A-frame and AR.JS libraries.
Here's the code I've tried, but the sound keeps playing indefinitely:
<a-scene embedded arjs='sourceType: webcam; debugUIEnabled: false;'>
<a-assets>
<audio id="sound" src="audio.mp3" preload="auto"></audio>
</a-assets>
<a-marker preset="hiro">
<a-entity id="examplemodel" gltf-model="./models/Example.glb" soundhandler></a-entity>
</a-marker>
<a-entity sound="src: #sound" autoplay="false"></a-entity>
<a-entity camera></a-entity>
</a-scene>
<script>
AFRAME.registerComponent('soundhandler', {
tick: function () {
var entity = document.querySelector('[sound]');
if (document.querySelector('a-marker').object3D.visible == true) {
entity.components.sound.playSound();
} else {
entity.components.sound.pauseSound();
}
}
});
</script>
When I changed 'tick' to 'init', I got this error message:
Uncaught TypeError: Cannot read property 'playSound' of undefined
Can anyone offer suggestions on how to fix this issue?