How to stop audio playing twice when tapped on android devices?

Hi Guys,

I'm trying to make a simple drum tap thing, and it works well in Safari and on iPhone. However, on both of my friends Android phones, one tap on the screen plays the hit twice.

It's got me stumped. Any tips for me?

var song, analyzer;

function preload() {
  song = loadSound('warble.wav');

function setup() {
  createCanvas(500, 1146);

  // create a new Amplitude analyzer
  analyzer = new p5.Amplitude();

  // Patch the input to an volume analyzer

function mouseClicked() {
  if (song.isPlaying()) {
    //do nothing!
  } else {;

function draw() {


  // Get the average (root mean square) amplitude
  var rms = analyzer.getLevel();

  //rectMode(CENTER);  // Set rectMode to CENTER
  ellipse(width/2, height/2, 100+rms*2500, 100+rms*2500);


 ellipse(width/2, height/2, 50+rms*1200, 50+rms*1200);

  // Draw an ellipse with size based on volume



  • edited October 2016

    Nice use of restart!

    Odd -- i can't test but the error sounds almost as if on Android the MouseClicked is getting called by both touchStarted() and again by touchEnded(). Have you tried changing the sketch from mouseClicked to touchStarted and testing that on touchscreen?

Sign In or Register to comment.