request = new XMLHttpRequest();
request.open('GET', 'storage/Sound1.mp4', true);
request.responseType = 'arraybuffer';
request.onload = function () {
var audioData = request.response;
audioCtx.decodeAudioData(audioData, function (buffer) {
console.log(buffer);
var duration = buffer.duration;
var sampleRate = buffer.sampleRate;
var length = buffer.length;
var channels = buffer.numberOfChannels;
var offlineCtx = new OfflineAudioContext(channels, length, 48000);
source = offlineCtx.createBufferSource();
myBuffer = buffer;
source.buffer = myBuffer;
source.connect(offlineCtx.destination);
source.start();
//source.loop = true;
offlineCtx.startRendering();
offlineCtx.oncomplete = function (e) {
var audioCtx = new(window.AudioContext || window.webkitAudioContext)();
var song = audioCtx.createBufferSource();
song.buffer = e.renderedBuffer;
song.connect(audioCtx.destination);
play.onclick = function () {
song.start();
}
console.log("completed!");
source.onended = function (e) {
console.log('ee');
console.log(e);
console.log(offlineCtx.state);
}
}
},
function (e) {
"Error with decoding audio data" + e.err
});
}
request.send();
on the examples and on "my code" source.onended fires when somebody click on stop btn. It's there any way to know when the song ends? The other way must be checking the the time < the duration. If somebody know something please! Thanks in advance
Aucun commentaire:
Enregistrer un commentaire