Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
web audio api and nested functions

I try to create an audiobuffer whose length depends on the length/duration of the audiofile.

I use the web Audio API https://webaudio.github.io/web-audio-api/#offlineaudiocontext

 function getDuration(filename) {
        // Send XHR request for audio file to server.
            const request = new XMLHttpRequest();
            request.open('GET', gorilla.stimuliURL(filename));
            request.responseType = 'arraybuffer';
            request.onload = function() {
                    // Decode the audio.
                audioContext.decodeAudioData(request.response, function(buffer) {
                        // Load and arm the source buffer.
                    var tStimNew = buffer.duration;
                });
            }
            request.send();
        }  

I get the duration of the audiofile using this function. I tested it and tStimNew is exactly what I expected. The problem seems to be that the variable tStimNew is only local to the function. But I would like to have the variable global to be able to use it further.

Where/how exactly do I have to include a return? The nesting of the three functions makes it too complex for me.

Thank you in advance!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda