gpt4 book ai didi

javascript - 错误 : Unable to decode audio data when playing sound onclick within A-frame Environment

转载 作者:行者123 更新时间:2023-11-30 14:40:43 25 4
gpt4 key购买 nike

我查看了类似问题的其他答案,不幸的是,我似乎无法弄清楚我的代码中需要更改什么。

这是我用来处理声音的组件:

// https://glitch.com/edit/#!/smiling-armchair
AFRAME.registerComponent('soccer-audiohandler', {
init:function() {
let playing = false;
var el = this.el;
let audioEl = document.querySelector("a-sound");
audioEl.setAttribute("src", "#soccer-game");

audioEl.addEventListener("loaded", (e) => {
console.log("AUDIO LOADED")
console.log(e)
var audio = audioEl.components.sound;
el.addEventListener('click', (ee) => {
console.log(ee)
if(!playing){
audio.playSound();
} else {
audio.stopSound();
}
playing = !playing;
});
})
}
})

这里是渲染组件的场景

<!DOCTYPE html>
<html>
<head>
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-environment-component@1.0.0/dist/aframe-environment-component.min.js"></script>
<script src="https://npmcdn.com/aframe-animation-component@3.0.1"></script>
<script src="https://npmcdn.com/aframe-event-set-component@3.0.1"></script>
<script src="https://npmcdn.com/aframe-layout-component@3.0.1"></script>
<script src="https://npmcdn.com/aframe-template-component@3.1.1"></script>
<script src="component/soccer-audiohandler.js"></script>
</head>
<body>
<!-- Try changing the preset to one of default, contact, egypt, checkerboard, forest, goaland, yavapai, goldmine,
threetowers, poison, arches, tron, japan, dream, volcano, starry, osiris. -->
<!-- See more environment options: https://github.com/feiss/aframe-environment-component#parameters -->
<a-scene cursor="rayOrigin:mouse" environment ="preset:goaland" >
<a-assets>
<a-sound src="some/path/here" id="soccer-game"></a-sound>
</a-assets>
<!--https://github.com/aframevr/aframe/blob/master/docs/components/geometry.md-->
<!--https://github.com/aframevr/aframe/blob/master/docs/components/sound.md-->
<a-text font="kelsonsans" value="click to play sound" width="8" position="0 2.25 -5" rotation="0 15 0"></a-text>
<a-sound geometry="primitive:box; width: 1; height: 1; depth: 1;"
position="1 1 -5"
autoplay="false"
soccer-audiohandler src='#soccer-game'></a-sound>
</a-scene>
</body>
</html>

我知道问题不在于路径,因为当我将它加载到 360 度图库中时音频播放正常,但它不会加载到上面的场景中。我试过使用 .wav 文件和 .ogg 文件。我也尝试缩短音频,因为原版很长。有人对我如何解决这个问题有任何建议吗?

最佳答案

你应该使用 <audio>而不是 <a-sound><a-assets> ,如所述here .

工作 fiddle here .

关于javascript - 错误 : Unable to decode audio data when playing sound onclick within A-frame Environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49713844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com