Aframe 添加按钮,允许声音在iphone vi a-frame上播放

Aframe 添加按钮,允许声音在iphone vi a-frame上播放,aframe,Aframe,我想在我的a-Frame应用程序中添加一个按钮来允许iphone上的声音,但我对HTML是新手,不知道怎么做。有人成功地做到了这一点吗?如果有,你能分享一些示例源代码吗 如何在开始屏幕上找到按钮,最好是在谷歌硬纸板/耳机图标旁边?我想出了一个方法,希望与大家分享。我为场景本身添加了一个单击事件,然后当您按下vr enter按钮(耳机图标)时,它会触发音频播放。在场景中,我添加了一个带有鼠标事件的扬声器图标,通过凝视来控制音频。我关闭img以打开/关闭声音。我没有在画布上的耳机图标旁边添加按钮,但

我想在我的a-Frame应用程序中添加一个按钮来允许iphone上的声音,但我对HTML是新手,不知道怎么做。有人成功地做到了这一点吗?如果有,你能分享一些示例源代码吗


如何在开始屏幕上找到按钮,最好是在谷歌硬纸板/耳机图标旁边?

我想出了一个方法,希望与大家分享。我为场景本身添加了一个单击事件,然后当您按下vr enter按钮(耳机图标)时,它会触发音频播放。在场景中,我添加了一个带有鼠标事件的扬声器图标,通过凝视来控制音频。我关闭img以打开/关闭声音。我没有在画布上的耳机图标旁边添加按钮,但我认为这样效果更好。如果你有更好的办法,我很想看看

<!DOCTYPE>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no,maximum-scale=1">
    <title>Sound Demo</title>
    <meta name="description" content="Audio Button Demo">
    <script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
  </head>
  <body>

<a-scene background="blue">
  <a-assets>
    <img id="soundButton" src="sourceimages/sound.png" >
    <img id="soundOffButton" src="sourceimages/soundOff.png" >
    <audio id="soundtrack" src="assets/Narration.mp3" preload="auto"></audio>
  </a-assets>

  <a-sky color="#00AEEF"></a-sky>

  <a-plane class="link" id="sButton" src="#soundOffButton" height="40" width="40" rotation="0 0 0" position="0 0 -300" material="transparent:true"
          event-set__1="_event: mousedown; scale: 1 1 1"
          event-set__2="_event: mouseup; scale: 1.2 1.2 1"
          event-set__3="_event: mouseenter; scale: 1.2 1.2 1"
          event-set__4="_event: mouseleave; scale: 1 1 1">
      </a-plane>


  <a-entity camera look-controls>
        <a-cursor id="cursor"
          color="white"

          animation__fusing="property: fusing; startEvents: fusing; from: 1 1 1; to: 0.1 0.1 0.1; dur: 1500"
          event-set__1="_event: mouseenter; color: cyan"
          event-set__2="_event: mouseleave; color: white"
          fuse="true"
          raycaster="objects: .link"></a-cursor>
  </a-entity>


</a-scene>


<script>

  var sbutt = document.querySelector('#sButton');
  var strack = document.querySelector('#soundtrack');

  sbutt.addEventListener('mouseenter', playButtonAudio);

  var scene = document.querySelector('a-scene');
  if (scene.hasLoaded) {
    playButtonAudio();
    } else {
      scene.addEventListener('click', playButtonAudio);
  }

  function playButtonAudio () {        
    if (strack.paused) {
      strack.play();
      sbutt.setAttribute('material', "src: #soundButton");          
    } else {
      strack.pause();
      sbutt.setAttribute('material', "src: #soundOffButton");          
    }
  }



</script>

声音演示
var sbutt=document.querySelector('sButton');
var strack=document.querySelector(“#原声带”);
sbutt.addEventListener('mouseenter',playButtonAudio);
var scene=document.querySelector('a-scene');
if(scene.hasload){
playbuttonudio();
}否则{
场景.addEventListener('click',playButtonAudio);
}
函数playbuttonudio(){
如果(strack.暂停){
strack.play();
sbutt.setAttribute('material',“src:#soundButton”);
}否则{
strack.pause();
setAttribute('material',“src:#soundOffButton”);
}
}