我需要發揮相關的音頻,並突出顯示相關的文本,當用戶點擊播放按鈕,它再次暫停,然後從相同點開始播放播放音頻和高亮文本與暫停選項
我有這個腳本,它使用音頻功能,但我不知道如何修改它,這樣它可以有停頓&玩遊戲功能
http://jsbin.com/juwoyidome/edit?html,output
<html><head>
<style>
#myAudio {
display: none;
}
span {
margin: 0px 10px;
}
.playing {
background: yellow;
}
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<audio id="myAudio">
<source src="" type="audio/mpeg">
</audio>
<button>Play Audio</button>
<p>
<span>Rooster</span>
<span>Cat</span>
<span>Horse</span>
<span>Elephant</span>
<span>Vulture</span>
<span>Duck</span>
</p>
<script type="text/javascript">
var audioIndex = 0;
var audioAddress = [
"http://audiomicro-dev.s3.amazonaws.com/preview/1030/caca5b5fcde48f9",
"http://audiomicro-dev.s3.amazonaws.com/preview/1030/9cd6976b1ce3b76",
"http://audiomicro-dev.s3.amazonaws.com/preview/1030/5d4ab0a4db5e7b4",
"http://audiomicro-dev.s3.amazonaws.com/preview/1030/0f5e54eda37e7f0",
"http://audiomicro-dev.s3.amazonaws.com/preview/1030/4597608ea80a312",
"http://audiomicro-dev.s3.amazonaws.com/preview/1030/6c4ae634173cc83"
];
$("button").click(function(){
audioIndex = 0;
playAudio(0);
});
$("#myAudio")[0].onended = function() {
audioIndex += 1;
playAudio(audioIndex);
};
function playAudio(index)
{
$("p > span").removeClass("playing");
$("#myAudio")[0].src = audioAddress[index];
$("#myAudio")[0].play();
$("p > span:nth-child(" + (index + 1) + ")").addClass("playing");
}
</script>
</body></html>
這是可以正常使用。謝謝。我試圖使用不正常工作的切換。 – Learning