本文介绍了在A-Frame中单击播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我很难找到一种解决方案来播放/停止/暂停点击声音,即当用黑框与A-Frame声音实体聚焦时...我想要的是一个平原,形状或者其上有播放/暂停图像的任何内容,这会在聚焦时触发音频。是否有人遇到类似的东西?
So I'm struggling to find a solution to play/stop/pause sound on "click" i.e. when focusing with a black dot with A-Frame sound entity... What I would like to have is a plain, shape or whatever with a play/pause image on it, which would trigger audio when focused. Did anyone encounter something similar perhaps?
<audio id="sound" crossorigin="anonymous" preload="auto" src="some-audio-file.mp3"></audio> ... would trigger something like sound="on: click; src: #sound"推荐答案
尝试制作自定义组件
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>您可以检查所有媒体方法,属性等此处。 您可以查看此按钮此处。
You can check all media methods, properties etc here. You can check this button here.
更多推荐
在A
发布评论