How to set condition to display time while playing mp3

Hi, I have the below output working in my hobby project which display the current time every second.

void PlayMp3file1()
{
   mp3_play (1);
   delay (17000);
   Serial.println("Playing mp3 song1");    
}

But because of simple code above, it stops the time display when the mp3 start to activate.
What I want is to set the time condition in the above code.
Furthermore I also want to blink an LED while the 17000 milliseconds song is playing.
Here's the working code to blink my LED:

void BlinkLed(){
  digitalWrite(led1,HIGH);
  delay(1000);
  digitalWrite(led1,LOW);
  Serial.println("Status: LED is blinking");         
}

In other words, while the 17,000 millisecond is playing, let the condition below happen:

void loop()
{
 t = rtc.getTime();   // Get data from the DS3231
 
 lcd.setCursor(0,0);
 lcd.print("Time: ");
 lcd.print(rtc.getTimeStr());
 delay(1000);

It will be easy for me to understand if somebody can translate my goal as below:

While the 17000 milliseconds songs is playing, display time using the code below:

lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
delay(1000);[/code]

and blink an LED also while playing.

i am not going to bother with your snippets, but I do wonder HOW you know the song is being played and when it ends? Is there some status indicator you are looking at?

Paul

If you want anything else to happen during the time the track is playing, you’ll have to look at alternatives to the delay(17000) statement which blocks most things. Hint: look at millis().

The song automatically plays at the specified date and time I set in the code using DS3132 RTC and related libraries. The song ends after the specified delay. I obtained the length of the mp3 by checking (playing) via VLC player. That's how I specify the delay time :slight_smile:

exactly it blocks everything. That’s what I need to find…I think the “While Loop Statement”. But I just don’t know how to do it.
It’s a sort of:
for k<17000 …

Maybe Using millis() for timing. A beginners guide and Demonstration code for several things at the same time can give you ideas.