Can someone help? Want to play a sound once from a loop

I'm constantly looping through JSON of live earthquake data to check if there's new data.

What I want to do is to play about a 20 second clip only once when there's new data. For each magnitude I will have a different sound. I've tried delaying the frameRate but it still will play the sound again as it's in the loop. Any way of fixing this?

JSONObject earthJSON;
JSONArray earth;

import ddf.minim.*;

Minim minim;
AudioSample sound;

int mag;
String placecheck = " ";
String place;
int startTime;

void setup() {

  size(512, 200, P3D);  
  minim = new Minim(this);
  sound = minim.loadSample( "sound.mp3");


void playSound(){
if (mag == 1){




void checkValue(){   
placecheck = place;



void draw() { 

  earthJSON = loadJSONObject("");

  earth = earthJSON.getJSONArray("features");

    mag = earth.getJSONObject(0).getJSONObject("properties").getInt("mag");
    place = earth.getJSONObject(0).getJSONObject("properties").getString("place");

    println("mag: " + mag);   
    println("place: " + place);

    if (place != placecheck){


void stop()



  • Can't you store a boolean that keeps track of whether you've already played the sound? Then only play the sound when the boolean is false.

  • Thanks for the suggestion but could you give an example of what you mean? I'm not overly experienced in Processing.

  • You should not rely on the frame rate to ensure the Json data isn't read too often. You should learn to use a timer with millis().

    This technique can also be used to control the delay between two sounds.

Sign In or Register to comment.