We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm checking if a value of a place changes but I only want the sound to play once from the loop and stop and then restart again if the next value of a place is the same. I will be having more than one sound in the end but right now I'm working off one. I'm not too experienced at Processing but I have been trying to it but not succeeding. Any help is much appreciated. It's basically the last step I need to finish this
JSONObject earthJSON;
JSONArray earth;
import ddf.minim.*;
Minim minim;
AudioSample sound;
boolean firstPlayThrough = false;
int mag;
String placecheck = " ";
String place;
int startTime;
void setup() {
frameRate(0.1);
size(512, 200, P3D);
minim = new Minim(this);
sound = minim.loadSample( "sound.mp3");
}
void playSound(){
if (mag == 1){
if(firstPlayThrough == false){
sound.trigger();}
}
}
void checkValue(){
placecheck = place;
playSound();
}
void draw() {
earthJSON = loadJSONObject("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson");
earth = earthJSON.getJSONArray("features");
//println(earth.size());
mag = earth.getJSONObject(0).getJSONObject("properties").getInt("mag");
place = earth.getJSONObject(0).getJSONObject("properties").getString("place");
println("_________________________");
println("mag: " + mag);
println("place: " + place);
if (place != placecheck){
if(sound.isPlaying() == false){
sound.pause();
if(firstPlayThrough == false) firstPlayThrough = true;}
}
if(firstPlayThrough == true){
sound.pause();//pause the current playback wherever it is
sound.cue(0);//set it at the start
sound.trigger();//play
}
}
void stop()
{
minim.stop();
}
Answers
PLEASE DON'T DO THIS. draw() runs up to 60 times a second by default. requesting that web page constantly like this is a terrible thing to do. you need to limit it.
http://earthquake.usgs.gov/earthquakes/feed/v1.0/quakeml.php says that the data is only updated every 5 minutes so you only need to check it that frequently.
How do I do that?
An example from this thread below:
http://forum.processing.org/two/discussion/1891/adding-intervals-for-fetching-rss-data
Don't make duplicate threads. I answered in the other thread, so you are diluting information and wasting efforts.