Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!