正如@ngokevin 所提到的,浏览器基本上不会自动播放任何东西,除非事先有用户交互。
对我有用的是从所有媒体(音频和视频)资产中删除自动播放,并创建一个通过单击按钮触发所有内容的功能。
<head>
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
<style>
#play-button{
position: fixed;
top: calc(50% - 1em);
left: calc(50% - 100px);
width: 200px;
height: 2em;
z-index: 10;
}
</style>
</head>
<body>
<button id="play-button">Begin Your Experience</button>
<a-scene>
<a-assets>
<!-- VIDEO AND AUDIO ASSETS -->
<audio id="n1" src="snd/narration.mp3" autoplay="false" preload="auto">
<video id="v1" src="video/sky.mp3" preload="auto" autoplay loop crossorigin webkit-playsinline></video>
</a-assets>
<!-- VIDEO AND AUDIO ENTITIES -->
<a-videosphere id="theVideo" autoplay="false" src="#v1" rotation="0 90 0" radius="400"></a-videosphere>
<a-sound id="theAudio" src="#n1" autoplay="false" position="0 0 0" volume="1"></a-sound>
</a-scene>
</body>
<script>
// Play button, required by browsers to grab user interaction before autoplaying videos.
document.querySelector('#play-button').addEventListener("click", function(e){
startStuff(); // launch the first voice over
this.style.display = 'none';
}, false);
function startStuff(){
var theVideo = document.querySelector('#n1');
theVideo.play();
var theAudio = document.querySelector('#v1');
theAudio.components.sound.playSound();
}
</script>