Tagged: , , ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2920
    Anonymous
    Inactive

    Hello!

    Is there any neat function that provides looping of the current song?

    Thank you

    #2922

    The below will repeat track one.


    while(1) {
    if(!MP3player.playTrack(1)) {
    while (MP3player.isPlaying());
    MP3player.stopTrack();
    }
    }

    But it will block.

    You can actually put

    MP3player.playTrack(1);

    in the loop and it will attempt to play track one, and if it is still playing it will simply respond with an error code. That can be ignored.

    #2923
    Anonymous
    Inactive

    I did this

    MP3player.playTrack(1);
    while(MP3player.isPlaying()) {
    MP3player.playTrack(1);
    }

    But I have a problem to change the track to a new with another selection, as for example:

    MP3player.playTrack(buttonSelection);
    while(MP3player.isPlaying()) {
    MP3player.playTrack(buttonSelection);
    }

    Which means that I want to have the current track looped, until a new selection is made

    #2926

    prehaps, something like the following, where it is up to you get define getselection();

    setup{
      if(!sd.begin(SD_SEL, SPI_HALF_SPEED)) sd.initErrorHalt();
      if(!sd.chdir("/")) sd.errorHalt("sd.chdir");
      MP3player.begin();
      prv_selection = selection;
    }
    
    loop{
      selection = getselection();
      if (()selection == 0) and (prv_selection != 0)) {
        MP3player.stopTrack();
        prv_selection = selection;
      }
      else if (selection != prv_selection) {
        MP3player.playTrack(selection);
        prv_selection = selection;
      }
      // do other stuff and then loop back around.
    }
    
    #2927
    Anonymous
    Inactive

    Unfortunately it didn’t work – I don’t know if someone else has tested it and it works? But I’m sure that it keeps reseting here prv_selection=selection in the loop function.
    Is there a function that reports when the track has finished playing so that I reset the track number? And then do something like this:

    if (buttonIn == 1){
    MP3player.stopTrack();
    MP3player.playTrack(1);
    }

    if (buttonIn == 2){
    MP3player.stopTrack();
    MP3player.playTrack(2);
    }

    #2928

    Look at my GIST example MP3ButtonPlayer.ino
    I just threw it together, it does compile and should (???) work. I have not tested it at this moment. Where as it is very simple. And uses the Bounce Library to make Debouncing easy.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.