How to play a sound for a set of number of times from DFPlayer_Mini_Mp3.h

Hi everyone! Please take your time and read through this and give me your solutions for the problems I am facing. I am trying to do a simple school project regarding a sprinkler system but I wanted to improve it by setting a number of times(example 3 times) to play a sound from my speaker to alert anyone nearby to stay clear because the sprinkler is about to turn on. Is it possible to do that because I couldn't find anything on google and if it is possible what is the code I need to put and where? Below is the code for the program:

#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>

SoftwareSerial mySerial(11, 10);

#define relay 2
#define interval 1000
// These constants won't change. They're used to give names to the pins used:
const int smSensor = A2; // Analog input pin that the soil moisture sensor (smSensor) is connected to

int sensorValue = 0; // declare sensorValue to store sensor readings later

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
mySerial.begin (9600);
mp3_set_serial (mySerial);
mp3_set_volume (15);

pinMode(relay, OUTPUT);
}

void loop() {
// read the analog sensor value and store in sensorValue.
sensorValue = analogRead(smSensor);

// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.println(sensorValue); // New line after every sensorValue displayed

// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);

if (sensorValue < 80)
{
mp3_play (6);
delay (6000);

digitalWrite(relay, HIGH);
delay(interval);
}
else
{
mp3_stop();

digitalWrite(relay, LOW);
delay(interval);
}
}

Thanks for taking the time to read this and sorry if this post was already published before!

Did you write the code ?

   mp3_play (6);
   delay (6000);

Is this the section of code that plays the alert ?
If so then what happens if you put it inside a for loop ?

UKHeliBob:
Did you write the code?
Nope. I got the code from my school website. !

   mp3_play (6);

delay (6000);




Is this the section of code that plays the alert?
Yes, that is the section of code that plays the alert.
If so then what happens if you put it inside a for loop?
How do you put it inside a for loop? Can you show me an example? Thanks!

Can you for starters post code that has a chance of compiling? The DF player object is never initialised, and you call some mp3_* functions that are not present in your code.

This is pseudo-code as best.

What you need is a for loop.

How do you put it inside a for loop? Can you show me an example?

From the nature of your question I would guess that you did not write the code. A for loop is such a fundamental concept that I would expect anyone who had written the code posted, albeit that it is incomplete, would know what a for loop was

Start with a Google search or better still find a C tutorial on line.