在A

编程入门 行业动态 更新时间:2024-10-28 14:30:48
本文介绍了在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

本文发布于:2023-07-11 09:37:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093607.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!