我有一个带有 A-frame 和 AR.JS 的站点,在其中我可以在标记检测时播放音频。但是,当标记在视图中时,我会在控制台中不断弹出此警报数次。
'components audio 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">'
它似乎要求每一帧/几帧。关于如何阻止这种情况的任何想法?这似乎是不好的行为,尤其是对于移动设备。
作为参考,这里是场景代码:
<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>
以及注册组件和事件的代码:
AFRAME.registerComponent('soundhandler', {
tick: function () {
var entity = document.querySelector('[sound]');
if (document.querySelector('a-marker').object3D.visible == true) {
entity.components.sound.playSound();
} else {
}
}
});