【问题标题】:A-Frame Sound Not PlayingA-Frame 声音未播放
【发布时间】:2021-06-17 04:33:27
【问题描述】:

我希望有人可以帮助我。我无法发出声音来播放。我是 A-Frame 的新手。我希望任何人都可以帮助我检查我的代码有什么问题:

<html>
  <head>
    <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
  </head>
  <body>
    <a-scene>
      <a-assets>
        <img id="sky" src="https://content.codecademy.com/courses/learn-a-frame/building-the-environment/mountains2.jpg">
        <img id="grass" src="https://upload.wikimedia.org/wikipedia/commons/f/f4/Light_green_oats_field.jpg">
        <a-asset-item 
          id="codey" 
          src="https://content.codecademy.com/courses/learn-a-frame/building-the-environment/codey.gltf"></a-asset-item>

<a-asset-item
          id="music"         
          src="https://cdn.aframe.io/basic-guide/audio/backgroundnoise.wav"
        ></a-asset-item>
      </a-assets>
      
      <a-sky src="#sky"></a-sky>
      <a-plane 
        src="#grass"
        rotation="-90 0 0" 
        width="20" 
        height="20"></a-plane>
      <a-entity
        text="value: Welcome!; color: #FFD500; align: center"
        position="0 3 -4"
        scale="6 6 6"
        animation="property: object3D.position.y;
          to: 3.2; 
          dir: alternate; 
          dur: 2000; 
          loop: true"></a-entity>  
      <a-entity 
        gltf-model="#codey" 
        position="0 2 -4" 
        scale="0.5 0.5 0.5"
        animation="property: object3D.position.y;
          to: 2.2; 
          dir: alternate; 
          dur: 2000; 
          loop: true"></a-entity>
      <a-light 
        type="point" 
        intensity="2" 
        position="2 4 4"></a-light>
       <!-- Add entity here: -->
       
       <a-sound
        src="#music"
        autoplay = "true"
        ></a-sound>

    </a-scene>
  </body>
</html>

我将此与 Codecademy 中提供的答案进行了比较。 Codecademy 实际上接受了代码但没有播放声音。我想我错过了一些东西,但我无法弄清楚。我尝试使用不同的浏览器,但仍然无法正常工作,所以我认为我的代码确实有问题,我很难弄清楚。

提前致谢!

【问题讨论】:

    标签: aframe


    【解决方案1】:

    它现在正在工作!看起来我错过了课程中未涵盖的 preload="auto" 属性。

    【讨论】:

    • 您能否将您的问题标记为已回答?
    • 感谢迭戈的提醒。我打算标记它,但网站说“你可以在 3 小时内接受你自己的答案”。一旦可以,我会标记它。否则,我可能会删除帖子。
    猜你喜欢
    • 2019-05-21
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    相关资源
    最近更新 更多