jeromeetienne / AR.js

Efficient Augmented Reality for the Web - 60fps on mobile!
MIT License
15.79k stars 2.22k forks source link

Crashing on mobile #338

Closed peterlunglum closed 5 years ago

peterlunglum commented 6 years ago

I'm getting the following alert in my console when I have a marker detecting a marker and playing audio.

'components:sound:warn All the sounds are playing. If you need to play more sounds simultaneously consider increasing the size of pool with the poolSize attribute. <a-entity sound=​"src:​ #sound" autoplay=​"false">​​'

I have the following script to attach the sound:

AFRAME.registerComponent('soundhandler', {
    tick: function () {
           var entity = document.querySelector('[sound]');
         if (document.querySelector('a-marker').object3D.visible == true) {
            entity.components.sound.playSound();
        } else {
        }

     }
});

Here's the code for my scene:

<a-scene embedded arjs='sourceType: webcam; debugUIEnabled: false;';>
       <a-assets>
            <audio id="sound" src="audio.mp3" preload="auto"></audio>
        </a-assets>
        <a-marker preset="custom" type="pattern" url="img/pattern-marker.patt">
        <!--<a-marker preset="hiro">-->
        <!--<a-torus-knot color="#000000" arc="180" p="2" q="7" radius="5" radius-tubular="0.1"></a-torus-knot>-->
                <a-box position='0 0.5 0' material='color: black;' soundhandler> 
                </a-box>
        </a-marker>
        <a-entity sound="src: #sound" autoplay="false"></a-entity>
        <a-entity camera></a-entity>
</a-scene>

It seems to register or detect the marker for every frame. Any ideas on what would cause this notification to popup constantly while the marker is in view?

vettorazi commented 6 years ago

idk if this is what you want, but try this:

var played: false; AFRAME.registerComponent('soundhandler', { tick: function () { var entity = document.querySelector('[sound]'); if (document.querySelector('a-marker').object3D.visible == true) { if (played==false){ entity.components.sound.playSound(); played=true; } } else { }

 }

});