Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda