Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Sound plays then stops?

$
0
0

I wrote a program to play audio randomly every 10 secs. It mostly works fine except after a few plays throught, even though my message comes in on the console, the audio stops playing.

import ddf.minim.*;

Minim minim;
/**every interval, the time is saved to here.
bysubtracting this from millis() we can see if another interval is reached*/
int savedTime;
//every 7seconds
int boreInterval = 10000;
boolean playTime=false;


  String[] Snap_Middle_fileNames ={
    "Samples/Snapper/Middle/bridge",
    "Samples/Snapper/Middle/goblins",
    "Samples/Snapper/Middle/painted",
    "Samples/Snapper/Middle/panAmerous",
    "Samples/Snapper/Middle/routCannal",
    "Samples/Snapper/Middle/sanAnchovies",
    "Samples/Snapper/Middle/spat",
    "Samples/Snapper/Middle/splatfest"
    };
  int numMiddle = Snap_Middle_fileNames.length;
  AudioPlayer[]  snap_middle = new AudioPlayer[numMiddle];

void setup(){
  size(200,200);
  background(0);

  savedTime=0;

  minim= new Minim(this);

  //load midlle
  for (int id = 0; id < numMiddle; id++){//cycles through the file ids
     snap_middle[id] = minim.loadFile(Snap_Middle_fileNames[id] + ".aif");//untill all are loaded
  }
}

void draw(){
    anti_monotony_timer();
    anti_monotony_player();
  }

//timer to make sure only one sample is triggered at a time
void anti_monotony_timer(){
  int timeSinceLastPlay= millis()-savedTime; /**savedTime is updated whenever a
  sample is played. The difference between that number and millis() tells the
  computer how many seconds have passed since the last play was triggered.*/
  if(timeSinceLastPlay>boreInterval){ //if the interval has passed
    playTime=true;//  play sound
    } else if(timeSinceLastPlay<boreInterval) {//if the interval has not passed
      playTime=false;//you can NOT play sound
    }
}

void anti_monotony_player(){
  int i;
  if(playTime==true){
    i=(int)random(numMiddle);
    snap_middle[i].play();
    savedTime=millis();
    println("Success!!!");
    println("function returned " + i);
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles