DFRobot / DFRobot_DF1201S

Here comes the DFPlayer Pro-a mini simple but powerful MP3 Player! This MP3 player module supports four controlling modes: Arduino, AT command, on-board buttons, and ADKEY. You can directly press the on-board button to play or switch music without using a controller. By using a USB cable, you can easily copy your favorite songs into this module to play them any where you want, or use it as a sound card for your PC or Raspberry Pi after connecting them together.
MIT License
6 stars 5 forks source link

ISPLAYING FUNCTION? #3

Open supermandt opened 2 years ago

supermandt commented 2 years ago

How can i see if music is currently playing? I have a button where if the music is playing, I want to stop it. then if you touch button again it will start playing the next track. The regular dfplayer mini has a function called isplaying() , does this DFROBOT PRO have a similar function? If not, we need this. Thanks.

Nickman87 commented 1 year ago

This method is not built in, but you can make one yourself:

bool mp3IsPlaying() {
  return DF1201S.getTotalTime() > DF1201S.getCurTime();
}
qsjhyy commented 9 months ago

Actually, the command 'AT+PLAY=PP\r\n' can directly achieve the functionality you need. image However, in the library, to make it easier to distinguish, we added a flag called 'pauseFlag.' In the future, I will use this flag to create an 'isplaying()' API. Thank you for your suggestion.

qsjhyy commented 9 months ago

@Nickman87, Thank you so much for your feedback! After my further testing, I found that when the current mode is set to DF1201S.setPlayMode(DF1201S.SINGLE);, the song will automatically stop after it finishes playing. This indeed can cause confusion with the flags in the code. So, I have added an interface with the hope of avoiding this situation. It will use getCurTime() to detect and refresh the flag.


bool DFRobot_DF1201S::isPlaying()
{
   uint16_t temp = getCurTime();
   delay(2000);
   if (getCurTime() != temp) {
      pauseFlag = 1;
   } else {
      pauseFlag = 0;
   }
   return pauseFlag;
}