WeekendWarrior1 / XTronical_XT_DAC_Audio_Mirror

Mirror of XTronical's excellent XT_DAC_Audio library for ease of integration into platformio projects
GNU General Public License v3.0
10 stars 18 forks source link

How to play multiple files only when triggered? #3

Open HasibAlAhmed opened 2 years ago

HasibAlAhmed commented 2 years ago

I have 2 files. I used two functions to play them

void play1(){
  int forceCounter=0;
  for(;;){
    DacAudio.FillBuffer();
    if(ForceWithYou.Playing==false)       // if not playing,
      DacAudio.Play(&ForceWithYou);
      forceCounter++;
    Serial.println(forceCounter);
    if (forceCounter>4500)
      break;
    }

  }
void play2(){
  int fCounter=0;
  for(;;){
    DacAudio.FillBuffer();
    if(Class.Playing==false)       // if not playing,
      DacAudio.Play(&Class);
      fCounter++;
    Serial.println(fCounter);
    if (fCounter>4500)
      break;
    }

  }

then in loop I tried to make them play one after another

void loop() {
  play1();
  delay (3000);        // Showing that the sound will play as well as your code running here.
  play2();
  delay (3000);  
}

but more often the 2 audios play simultaneously.

How can I clear the buffer after each portion gets played?