目前我設計的Tizen Web應用程序(遊戲),我想:播放音頻一段時間,另一個聲音結束後,同時在for循環
- 顯示圖像
- 播放音頻剪輯(大約15-17秒長)
- 什麼都不做,持續5秒
- 另一個播放音頻剪輯(約2-3秒)
- 隱藏圖像
這些步驟將按順序循環執行(N次)。但是,當我在模擬器上運行我的應用程序時,它將同時播放步驟2中播放的所有聲音,同時圖像永遠不可見。
以下是我的javascript功能:
function performTask(image, audioName) { //sending id for image and audio, e.g.: performTask("img1", "aud1")
// Show the image
img = document.getElementById(image);
if (img && img.style) {
img.style.height = screen.height;
img.style.width = screen.width;
img.style.visibility = "visible";
} else {
console.log("exercise(): error in setting image");
}
// play the audio
try {
myAudio = document.getElementById(audioName);
myAudio.play();
myAudio.onended = function() {
timeOut();
};
} catch (error) {
console.error("exercise(): " + error.message);
}
// after 30 seconds, ring the bell!!
try {
console.log("playing bell");
document.getElementById("bell").play();
} catch (error) {
console.error("bell: " + error.message);
}
//hide image
img.style.visibility = "hidden";
}
超時()函數:
...
<body onload="someFunc()"> <!-- this calls performTask() in a for-loop-->
<p>
<img src='images/image1.png' alt="pose1n12" id="img1" />
.... 10 more such images
</p>
<p>
<audio id="bell">
<source src='audio/bell.mp3' type="audio/mpeg" />
</audio>
<audio id="aud1">
<source src='audio/aud1.mp3' type="audio/mpeg" />
</audio>
.... 10 more such clips
</p>
編輯:
var timer = 5000;
function timeOut() {
if (timer > 0) {
setTimeout(timeOut(), timer--);
}
}
哪裏這就是所謂的HTML頁面的結構:添加someFunc的定義()
function someFunc() {
var a;
image = ''; // select image at particular count
audioName = ''; // select respective audio
for (a = 1; a <= 12; a++) { // the asana tracker loop
switch (a) { // assigns image & audio
case 1:
image = "img1n12";
audioName = "1N12";
break;
...... continues till case 12
}
}
performTask(image, audioName);
}
請幫忙。
設置的事件偵聽器在音頻完成'的document.getElementById(「鍾」)的addEventListener(「結束」,函數(){//此處一些代碼的改變src});'你可以有此運行一個函數或調用另一個函數。 – NewToJS 2015-03-03 12:22:33
@NewToJS較早試了一下,沒有運氣 – user2281204 2015-03-05 04:40:37
這樣看來,你有你的問題,甚至複雜的事情擴大。一旦當前音頻結束後,你不想知道如何播放另一個音頻文件嗎?我相信這是原來的問題... – NewToJS 2015-03-05 10:30:32