web audio не проигрывает
Хочу разделить загрузку и проигрывание, чтобы после нажатия стоп, затем старт проигрывание пошло сразу без загрузки.
var context; var bufferLoader; var souce1,source2,buf1,buf2; function init() { console.log('Loading...'); context = new window.AudioContext(); bufferLoader = new BufferLoader( context, [ 'audio/1.mp3', 'audio/2.mp3', ], toBuf ); bufferLoader.load(); } function toBuf(bufferList){ buf1=bufferList[0]; buf2=bufferList[0]; play(); } function play() { if (buf1&&buf2){ // Create two sources and play them both together. source1 = context.createBufferSource(); source2 = context.createBufferSource(); source1.buffer = buf1; source2.buffer = buf2; source1.connect(context.destination); source2.connect(context.destination); source1.start(0); console.log('Start'); source2.start(0); } else { init(); } } function stop() { source1.stop(0); source2.stop(0); } var plbtn = document.getElementById('playBtn'); if(plbtn){ plbtn.addEventListener('click', play); } var stopbtn = document.getElementById('stopBtn'); if(stopbtn){ stopbtn.addEventListener('click', stop); } Почему не проигрывает? |
Часовой пояс GMT +3, время: 18:48. |