I am using a ESP32 (Library: DFPlayerMini_Fast.h) to control a DFplayer Mini.
Basically everything works fine.
The "BUSY" signal of the DFPlayer and an input-pin of the ESP32 is used, to detect the end of a playing the regular sound-files.
My question:
How can the ESP32 detect the end of playing an "advertising-sound-file" while still playing the regular sound-file?
Details:
Playing an "advertising-sound-file" pauses an already playing regular-sound-file and resumes the regular sound file immediately after the "Advertisement" has finished. The "BUSY" signal remains in the BUSY-State all the time. The ESP32 needs to be able to detect the end of playing the Advertisement in order to immediately start some other action.
You probably can’t do it !
However , to do it you need to find something that identifies the adverts as being different to music and work on that ( eg a signal that appears before an Ad , if it exists )
There is a signal which starts the Ad, but I need to detect the end of the Ad to start the next action.
As there is no means of getting this info from the DFPlayer, I am now thinking of using a timer running on the ESP32.
The timer will be just a little bit longer than the duration of the AD and it will be started with the start of the Ad. after the timer (and the Ad) has finished, the ESP32 will start the next action.
It is not a very flexible solution, because evry time the duration of the Ad is changed, the timer needs to be changed. However, the Ad will not be changed anymore after everything is finished.
With the attached test-program (runs continuously in the loop) the status of the BUSY-signal behaves in 2 different versions:
a) The BUSY-signal gets LOW with the start of sound 01 (start of loop). With the start of the AD, the BUSY-signal switches from LOW to HIGH for about 300 ms and then back to LOW. It stays LOW while the AD is playing. As soon as the AD is finished, the BUSY-signal switches from LOW to HIGH for about 300 ms and then back to LOW. Then the sound 01 continues and the BUSY-signal stays LOW until the sound 01 gets stopped.
b) The BUSY-signal gets LOW with the start of sound 01 (start of loop). Then the BUSY-signal stays LOW all the time from the start of the loop until the end of the loop without changing to HIGH when starting the AD or resuming the sound 01. With the STOP of the sound 01 (end of the loop) the BUSY-signal changes to HIGH.
While the loop continuously runs, the system sometimes shows behavior a) and sometimes behavior b). Sometimes it shows the same behavior (a) or b)) several times in a row and sometimes the behavior changes between a) and b) with every loop.
It would be nice if the system would always show behavior a). This would allow to detect the end of the AD precisely and independent of the length of the AD.
The same behavior shows up with 2 DFPlayer mini.
Can anybody tell me, if the described behavior is a problem of the DFPlayer mini itself o if it is caused by my code?
void loop()
{
int songnummer = 01;
digitalWrite(light05, HIGH);
myMP3.playFromMP3Folder(songnummer); // Start MP3 SOUND 01
delay(dfplayer_wait); // 333 ms
delay(3000); //listen to sound 01 for 3 seconds
digitalWrite(rauchventil25, HIGH);
songnummer = 64;
myMP3.playAdvertisement(songnummer); // AD lasts 3 seconds
delay(dfplayer_wait);
delay(4000); // wait to finish AD
digitalWrite(rauchventil25, LOW);
delay(3000); // listen to sound 01for 3 seconds
myMP3.stop(); // stop MP3 Sound 01
delay(dfplayer_wait);
digitalWrite(light05, LOW);
delay(3000); // no sound for 3 seconds
}
Yes, AD- and sound-files are on the SD card in designated directories (advert and mp3).
Unfortunately I can't delete them, becuase they are needed.
With the final version of the sketch, I would even like to run several ADs during a "long" soundfile.
This is a described feature of the DFPlayer mini in the product description.
Playing ADs with pausing and resumiung soundfiles works fine.
My problem is the detection of the end of the ADs by the software. As of the problem described above, the sketch can not reliable detect the end of the ADs.
Any other suggestions for solving the problem or performing the task?