В настоящее время я разрабатываю веб-приложение (игру) на Tizen, где я хочу:
- Показать изображение
- Воспроизвести аудиоклип (длиной около 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";
}
Функция timeOut():
var timer = 5000;
function timeOut() {
if (timer > 0) {
setTimeout(timeOut(), timer--);
}
}
Структура HTML-страницы, где это вызывается:
...
<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>
EDIT: Добавление определения для 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("bell").addEventListener("ended",function(){//Some Code here to change the src});
Вы можете запустить функцию или вызвать другую функцию. - person NewToJS   schedule 03.03.2015