我正在研究基于 A 框架的讲故事结构。
我将语音文件分成 3 个部分,目标是仅在满足正确条件时触发序列中的每个音频。
我试过 nar1.addEventListener('sound-ended',newCurrent) 没有运气。为了简化事情,我将省略条件:
<!DOCTYPE html>
<html class="a-html">
<head>
<meta charset="utf-8">
<title>Panorama</title>
<meta name="description" content="Panorama — A-Frame">
<meta name="apple-mobile-web-app-capable" content="yes">
<script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
</head>
<body>
<button id="play-button" class="centerPos">Begin Your Experience</button>
<a-scene vr-mode-ui="enabled: true" stats>
<a-assets>
<!-- SOUNDS -->
<audio id="n1" src="snd/dt_narration_1.mp3" preload="auto">
<audio id="n2" src="snd/dt_narration_2.mp3" preload="auto">
<audio id="n3" src="snd/dt_narration_3.mp3" preload="auto">
</a-assets>
<!-- SOUNDS -->
<a-sound id="nar1" src="#n1" autoplay="false" position="0 5 0"></a-sound>
<a-sound id="nar2" src="#n2" autoplay="false" position="0 5 0"></a-sound>
<a-sound id="nar3" src="#n3" autoplay="false" position="0 5 0"></a-sound>
</a-scene>
</body>
</html>
<script>
// sound assets
var nar_1 = document.getElementById('n1');
var nar_2 = document.getElementById('n2');
var nar_3 = document.getElementById('n3');
// a-sound entities
var nar1 = document.getElementById('nar1');
var nar2 = document.getElementById('nar2');
var nar3 = document.getElementById('nar3');
// listeners attached to entities
nar1.addEventListener("sound-ended", newCurrent);
nar2.addEventListener("sound-ended", newCurrent);
nar3.addEventListener("sound-ended", newCurrent);
// Play button, required by browsers to grab user interaction before autoplaying videos.
document.getElementById('play-button').addEventListener("click", function(e){
nar_1.play(); // launch the first voice over
this.style.display = 'none';
}, false);
function newCurrent(){
// if conditions are met and its not the last audio, trigger next audio.
console.log("story control enter. You made it!");
}
</script>