c-frame / aframe-extras

Add-ons and helpers for A-Frame VR.
https://c-frame.github.io/aframe-extras/examples/
MIT License
972 stars 308 forks source link

Play Audio on Marker Detection #227

Closed peterlunglum closed 6 years ago

peterlunglum commented 6 years ago

I'm trying to play sound when a marker is detected but it currently isn't working. From other issues I tried the following:

` var entity = document.querySelector('[sound]');

AFRAME.registerComponent('markerhandler', {
   tick:function() {
      if(document.querySelector("a-marker").object3D.visible == true) {
      // MARKER IS PRESENT
            entity.components.sound.playSound();
      } else {
      // MARKER IS HIDDEN
            entity.components.sound.pauseSound();
      }
   }
});

`

With the scene being:

    <a-scene embedded arjs='sourceType: webcam; debugUIEnabled: false;';>
        <a-marker preset="hiro">
                <a-box position='0 0.5 0' material='color: black;'></a-box>
        </a-marker>
        <a-assets>
            <audio id="sound" src="audio.mp3" preload="auto"></audio>
        </a-assets>
    <a-entity sound="src: #sound" autoplay="false"></a-entity>
    <a-entity camera></a-entity>
    </a-scene>

Doesn't seem to register. Any ideas as to why?

donmccurdy commented 6 years ago

This seems like a workaround to https://github.com/jeromeetienne/AR.js/issues/217 and not related to aframe-extras, I think you will need to follow up there. I do not use AR.js myself.