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

140
Visualizações
AudioContext and animation do not work on iPhone

I have this little code snippet here

var context = new(window.AudioContext || window.webkitAudioContext)();
.....
var source = context.createMediaElementSource(audio);
var analyser = context.createAnalyser();

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

source.connect(analyser);
analyser.connect(context.destination);
analyser.fftSize = 256;

var bufferLength = analyser.frequencyBinCount;

var dataArray = new Uint8Array(bufferLength);

var WIDTH = canvas.width;
var HEIGHT = canvas.height + (canvas.height * 0.7);

var barWidth = (WIDTH / bufferLength) * 2.5;
var barHeight;
var x = 0;


function renderFrame() {
  x = 0;
  ctx.fillStyle = "#000";
  ctx.fillRect(0, 0, WIDTH, HEIGHT);
  analyser.getByteFrequencyData(dataArray);

  for (var i = 0; i < bufferLength; i++) {
    barHeight = dataArray[i];
    var r = barHeight + (25 * (i / bufferLength));
    var g = 250 * (i / bufferLength);
    var b = 50;
    ctx.fillStyle = "rgb(" + r + "," + g + "," + b + ")";
    ctx.fillRect(x, HEIGHT - barHeight, barWidth, barHeight);
    x += barWidth + 1;
  }
  requestAnimationFrame(renderFrame);
}
requestAnimationFrame(renderFrame);


audio.src = jQuery("source").attr("src");
audio.play();

Full code and demo here: https://jsfiddle.net/6gv39mk0/1/show

That basically shows a dynamic waveform when audio is played

enter image description here

It works on desktop browser, android browser, but no way to make it works on iPhone. Am I missing something or is there something that I must declare/do differently?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I've solved this issue with a transparent button on top of play button. this probably make iPhone browsers understand that there is an interaction. After that the button is hidden (z-index -1) It's not that elegant as solution, but it work!

  var button = document.createElement('button');
    jQuery(button).attr('id', 'btn');
    jQuery(canva).before(button);
    jQuery(button).on('click', function() {
        start();
      jQuery(button).remove();
    })

here it is the fiddle https://jsfiddle.net/L1trwz7o/

about 4 years ago · Juan Pablo Isaza Relatório
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