Series of audio files to play in DF Player

In DF Player

Want to play a series of 2 files in such a way that

First file will play once fully and

Second file will jsut after that and keep running continously in a loop

So tried with one below :

if (digitalRead(IN22)==LOW)
  {
    player.play(1);
    player.disableLoop();
    player.play(2);
    player.enableLoop();
  }

But it plays the first file for 2 3 seconds hardly and then comes to second one with a small time gap

Then plays second one as per command

please guide

Anas Kuzechie shows how he cascaded from one file to the next with a pushbutton (you could remove the pushbutton routine for your project):

Ya I already worked with that in very first step while begining with DF Player module

Then I tried to add this button system to make a music player with a matrix keypad and button and etc etc things

So now want to add some feature within that !!!

Okay. You solved the button system. Very good.

Ya but this type of feature I want to add in my system so asked about the solution in this thread . . please guide !!

Okay. You want to add the "play(1)" then "play(2)" without the problem with "play(1)" being only 2-3 seconds (you want the full file). Would you post your full sketch so we can see how it is configured?

Yes yes that one I want to have Sir :slight_smile:

Surely I ll post the simplest code I am working on .. ..

Now I am out of town but surely I ll post it tomorrow as I am not carrying my system right now !!

Okay. Tomorrow.

Ya Sir sure

Will try to get in home soon!!

Ya Sir I am Home & code is here

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial softwareSerial(15, 14); // RX, TX
DFRobotDFPlayerMini player;
const byte IN22 = 22;
boolean readValue22 ;
void setup() 
{
  softwareSerial.begin(9600);      //  * D F  P L A Y E R * 
  if (player.begin(softwareSerial)) 
  {
    Serial.println("OK");
    player.volume(22); //30 is very loud
  } 
  else 
  {
    Serial.println("Connecting to DFPlayer Mini1 failed!");
  }
    pinMode (IN22, INPUT_PULLUP);
  }
void loop() 
  {
  if (digitalRead(IN22)==LOW)
  {
    player.play(1);
    player.disableLoop();
    player.play(2);
    player.enableLoop();
    while(digitalRead(IN22)==LOW);
  }
}

Please guide me in creating the feature !!
Thanks !!

I found a note on an incomplete project that says to put a delay() immediately after starting an audio file for the play length, so a file of 4min20sec play would use 260,000 ms delay...

player.play(1);
delay(260000);

"... Delay(seconds); You have to specify number of seconds delay for the audio file to play completely or the next audio file might be started before current audio is over!..."

on this page:

And, on this page:

The reference to usable pin numbers if interrupts are used on a Mega2560 (in your code, IN22) says...

"...Not all pins on the Mega and Mega 2560 boards support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)..."

Yeah I followed this and did with PIN 50 but no change same result again

So Now how to calculate this one

player.play(1);
delay(260000);

The length of file with delay timing ???

Any chart type thing available ??

The command delay(1); stops the program from advancing for 1 (one) millisecond.
A command of delay(1000); stops the program from advancing for 1000ms or 1 second.

You only need the length of time the player.play(1) is expected to play. My example was 4 minutes 20 seconds, which calculates to 260,000 milliseconds [delay(260000].

audio time: 4m 20s
audio time in seconds: 4 minutes * 60 seconds/minute + 20 seconds = 260seconds
audio time in milliseconds: 1000ms/s * 260s = 260,000 ms
unsigned long m = 4; // 4 minutes
unsigned long s = 20; // 20 seconds
unsigned long ms; // resulting milliseconds

void setup() {
  ms = ((m*60)+s)*1000;
  Serial.begin(9600);
  Serial.print("Audio file length of ");
  Serial.print(m);
  Serial.print(":");
  Serial.print(s);
  Serial.print(" is ");
  Serial.print(ms);
  Serial.println(" milliseconds.");
}

void loop() {}
Audio file length of 4:20 is 260000 milliseconds.

With as usual old code I gone through practicals with PIN 50 and result is like :

I create a small file of length 14.222 (as per sound forge)

In milisec its as usual 14222 as we know

But with delay value near about 13600 its working as full length but not very sure about this

The reason is :

There is always a very small gap between 2 files so its not easy to understand that the first file is playing fully up to the very end practical value or not, before the second file

Coming to next matter :

when this type of button carrying such a command is pressed , then no other button works within the time of play for first file

Like stop button or any other button with other command for any other file to play say PIN 51 or PIN 52

Right now while typing this case study I am trying to adjust the proper value of delay so as to play the very first file fully

Then I am about to move for your code of unsigned long

Thanks . . .ll let you know

But please help me in removing above errors I got after experimenting for hours !!!!!!!!!!

14.222 seconds or 14 minutes and (.222 * 60) seconds (13.32 seconds)?

I think delay() drifts about 1ms in 5000ms (3ms in 15000ms), but I do not know why you see 600ms drift in 14222ms of audio. This small sketch should show the drift of delay();:

void setup() {
  Serial.begin(9600);
  while (1) {
    delay(1000);
    Serial.println(millis());
  }
}
void loop() {}

and

void setup() {
  Serial.begin(9600);
}
void loop() {
  delay(1000);
  Serial.println(millis());
}

Ya its a short one
14.222 seconds file just for experiment purpose

Ok sure
ll check it for this intro in setup and update

With this code below :

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
  while (1) {
    delay(1000);
    Serial.println(millis());
  }
}

void loop() {
  // put your main code here, to run repeatedly:
delay(1000);
  Serial.println(millis());
}

Got this sample list on serial monitor

Yes. This shows the "drift" of delay(). Each number is a few ms off.

So whats the solution for this one ??

I too observed that a trance beat DJ loops on its very first loop play starts with a gap or delay of say a 1ms at end of file after its first play and then it continue the loop with no delay no gap and simple loop play as we find in case of an SD card module

Only issue with SD Module is that :

It produce a spark type sound at the starting of any audio file

The disturbing sound is just like some one is powering up a device or amplifier unit with speakers connected
Just like an electrical spark or noise due to mechanical switching

This thing is observed heavily or SD Module is the best one for a loop play with fast response

I did practicals with touch switch also but same spark sound at the beginning of a random audio wave file

Is anything we can do on DF or SD modules ??

Please guide