Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Web Audio API (https://javascript.ru/forum/misc/44763-web-audio-api.html)

KupueIIIKo 01.02.2014 12:12

Web Audio API
 
// создаем аудио контекст
if (typeof AudioContext == "function") {var audioContext = new AudioContext();
}else if(typeof webkitAudioContext == "function") {var audioContext = new webkitAudioContext();}
var source = audioContext.createBufferSource();
source.connect(audioContext.destination);

var xhr = new XMLHttpRequest();
xhr.open("GET", "sound/open.wav", true);
xhr.responseType = "arraybuffer";
xhr.onload = function() {
    var buffer_open = audioContext.createBuffer(xhr.response, false);
    source.buffer = buffer_open;
};
xhr.send();

// функция начала воспроизведения
var play_open = function(){
  // воспроизводим
  source.start(0);
}


Воспроизводится при клике на кнопку все отлично! Есть одна проблема, при втором клике вылетает ошибка!
"Failed to execute 'start' on 'AudioBufferSourceNode': cannot call start more than once."

Вопросы как отследить что звук проигрался?
или просто перезапустить буфер?

melky 01.02.2014 15:16

https://dvcs.w3.org/hg/audio/raw-fil...fferSourceNode

KupueIIIKo 01.02.2014 15:18

melky,
По английскому 2 )

Яростный Меч 01.02.2014 18:00

Цитата:

Сообщение от KupueIIIKo
По английскому 2 )

вкратце - у твоего объекта source есть событие onended, которое случается, когда звук проигрался.


Часовой пояс GMT +3, время: 17:53.