Edzelf / ESP32-Radio

Internet radio based on ESP32, VS1053 and a TFT screen.
GNU General Public License v3.0
973 stars 229 forks source link

Play once and then stop #341

Open blotfi opened 4 years ago

blotfi commented 4 years ago

Here is how I start playing an MP3 file,

    if (!SD_okay) return;                                // SD card present?
    if (datamode & (HEADER | DATA | METADATA | PLAYLISTINIT |
                    PLAYLISTHEADER | PLAYLISTDATA)) {
        datamode = STOPREQD;                           // Request STOP
    }
    host = "localhost/myfile.mp3";       // Save it for storage and selection later
    hostreq = true;                                  // Force this station as new preset

but how to make the play stop just after that

 datamode = STOPREQD;                           // Request STOP

how can I detect that the play is finished

blotfi commented 4 years ago

figure it out

in the mp3loop(), I added


  if ( localfile )                                       // Playing from SD?
  {
    if ( datamode & DATA )                               // Test op playing
    {
      if ( av == 0 )                                     // End of mp3 data?
      {
        datamode = STOPREQD ;                            // End of local mp3-file detected
          if (Flags.myfileplayed== 1) {
              datamode = STOPREQD;        // stop after myfile
              Flags.myfileplayed= 0;
          }
        else {
              if ( playlist_num )                              // Playing from playlist?
              {
                  playlist_num++ ;                               // Yes, goto next item in playlist
                  datamode = PLAYLISTINIT ;
                  host = playlist ;
              }
              else
              {
                  nodeID = selectnextSDnode ( SD_currentnode,
                                              +1 ) ;             // Select the next file on SD
                  host = getSDfilename ( nodeID ) ;
              }
              hostreq = true ;                                 // Request this host
          }
      }
    }
  }