所以我很难找到一种解决方案来播放/停止/暂停“点击”声音,即当用黑框与A-Frame声音实体聚焦时...我想要的是一个平原,形状或者其上有播放/暂停图像的任何内容,这会在聚焦时触发音频。有没有人遇到过类似的东西?
<audio id="sound" crossorigin="anonymous" preload="auto" src="some-audio-file.mp3"></audio>
... would trigger something like sound="on: click; src: #sound"
答案 0 :(得分:3)
尝试制作自定义组件
AFRAME.registerComponent('audiohandler', {
init:function() {
let playing = false;
let audio = document.querySelector("#audio");
this.el.addEventListener('click', () => {
if(!playing) {
audio.play();
} else {
audio.pause();
audio.currentTime = 0;
}
playing = !playing;
});
}
})
并在“你的按钮”
中使用它<a-box audiohandler> </a-box>