Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 25 of 25

Thread: Frank's MP3 Player2 Question

  1. #1

    Frank's MP3 Player2 Question

    I'm trying to test Frank B's MPG3 Player2 example code and cannot hear any sound out of the audio line output which I assume would be present when running the sketch with recorded MPG3 music on the SD card. However, no sound is present and the monitor lists each of the 5 songs being accessed is rapped sequence. I have not altered the code except to comment out the setup and main loop reference at the bottom (see attached sketch). The monitor lists the following which :

    Click image for larger version. 

Name:	Frank_B_MPG3_Player2_Messages.PNG 
Views:	76 
Size:	12.7 KB 
ID:	16024

    Also, I'm wondering about the usage of EEPROM to store the track position:

    void playFileMP3(const char *filename)
    {
    Serial.print("Playing file: ");
    Serial.print(track);
    Serial.print(" - ");
    Serial.println(filename);
    trackchange = true; //auto track change is allowed.
    // Start playing the file. This sketch continues to
    // run while the file plays.
    EEPROM.write(0,track); //meanwhile write the track position to eeprom address 0
    playMp31.play(filename);


    // Simply wait for the file to finish playing.
    while (playMp31.isPlaying()) {
    // update controls!
    controls();
    serialcontrols();
    }
    }

    If the track # is written every time a new track is accessed and code is run over a long period of time, wouldn't this reduce EEPROM life expectancy? It seems a RAM location could be used instead. Any thoughts on this?
    Attached Files Attached Files

  2. #2
    Sorry, I'm using the T3.2 with Audio Shield and running Arduino 1.8.5 with Duino 1.4.2. Audio Shield is stacked on T3.2.

  3. #3
    Wondering about something that might explain issue of not playing songs. In Frank's setup code he is looking for file extension with 1st character .M for MP3 or .A for AAC (see code segment below). If the file name does not have this extension, could that cause the file not play even though the monitor prints MP3 for type? Windows directory listing does not show this extension, but maybe it is really there.

    while(true) {

    File files = root.openNextFile();
    if (!files) {
    //If no more files, break out.
    break;
    }
    String curfile = files.name(); //put file in string
    //look for MP3 or AAC files
    int m = curfile.lastIndexOf(".MP3");
    int a = curfile.lastIndexOf(".AAC");
    int a1 = curfile.lastIndexOf(".MP4");
    int a2 = curfile.lastIndexOf(".M4A");
    //int w = curfile.lastIndexOf(".WAV");

    // if returned results is more then 0 add them to the list.
    if(m > 0 || a > 0 || a1 > 0 || a2 > 0 ){

    tracklist[tracknum] = files.name();
    if(m > 0) trackext[tracknum] = 1;
    if(a > 0) trackext[tracknum] = 2;
    if(a1 > 0) trackext[tracknum] = 2;
    if(a2 > 0) trackext[tracknum] = 2;
    // if(w > 0) trackext[tracknum] = 3;
    Serial.print(m);
    tracknum++;
    }
    // close
    files.close();
    }

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    The file extension must be present, and correct.
    It plays all files if they are encoded correctly:
    44100Hz, max two channels, 16bit. Sometimes metadata like included pictures can cause trouble. remove them with a tool of your choice. If you still have trouble playing a file, please contact me via mail and send me that file.

  5. #5
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    Quote Originally Posted by Frank B View Post
    The file extension must be present, and correct.
    It plays all files if they are encoded correctly:
    44100Hz, max two channels, 16bit. Sometimes metadata like included pictures can cause trouble. remove them with a tool of your choice. If you still have trouble playing a file, please contact me via mail and send me that file.
    Edit: Some time ago, I added testfiles - you can find them in examples/testfiles.

  6. #6
    Frank, thanks for your support on this issue. I look under File/Examples and did not find "testfiles" as a listing in the Arduino IDE menu. I'm running Arduino 1.8.5 with Teensyduino 1.4.2. Do I need to update the software or is this on forum.pjrc.com? I tried converting a .wav file to .mp3 and .aac format using Switch Plus audio converter by NCH with audio tags turn off, but same results as before. I would think a wave file would have no metadata embedded in it, but maybe it does.

    In any event, is there code that can be used to automatically ignore or skip over any metadata before play begins. The reason I'm asking this is if I'm designing a product that the general public will use, I wouldn't want them to have to use software to strip out embedded metadata just to play a prerecorded song.

  7. #7
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,090
    Maybe you need to get the updated library. It looks like there are 4 MP3 files in examples/testfiles that were added 4 months ago:

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    I wrote "sometimes".. that means yes, it tries to skip metadata.
    Without having one of your not working files, i can't help you.
    95%of problems with this lib were wrong usage.
    Do you have enough RAM free?
    Last edited by Frank B; 03-02-2019 at 08:35 PM.

  9. #9
    Frank, I updated Teensyduino to version 1.4.5 and searched for File/Examples/Testfiles under the drop down menu. Still could not find them listed. In any event, I tried to upload a couple of the mp3 audio files for you to test in a zip file, but could not with "manage attachments". Not sure why this is happening. Maybe the only way to get them to you is via email, but don't have your email to send them.

    I have tried to convert these .mp3 files to .aac using the Switch Plus converter from NCH with audio tags turned off which I think would eliminate metadata, but maybe not. Of course, converted Wave files of these songs work fine with the normal audio.h library.

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    - The CODECS lib is NOT part of teensyduino
    - No, mp3 files are not displayed in the Arduino menu.. of course not - would that make any sense? Open the explorer and go the libs subdirectory. On Github, they are here: https://github.com/FrankBoesing/Ardu...ples/testfiles
    - Upload:Yes, I wrote "send a mail"... it's everywhere.Ok... for the spammers :-( here it is again: f.boesing -AT- gmx -DOT- de - and now please don't say you don't understand this syntax... please send only one file. - But please test the testfiles first!
    - I don't know the "Switch Plus" converter, and have never used it.

  11. #11
    I downloaded the 4 example/testfiles, tested them to make sure they played the songs, tranferred them on a Sandisk 16 GB SD card, compiled and programmed the Frank_B_MP3_Player2 sketch on a new Teensy 3.2 and Audio Shield board. The same rapid listing in serial monitor of files being accessed, but not played. So it appears it is not the .mp3 files that is the problem. I tried this on another set of SD card (same example songs), Teensy 3.2 and Audio Shield. I don't have the 3 buttons connected on the breadboard for next, previous or pause to inputs 2, 3 and 4. But since they are pull high, I don't think that would prevent it from playing the songs. As to your comment about free RAM, since this is an un-modified sketch (except for the "user" main loop and setup at the bottom) I don't think should be a problem either. Any ideas?

  12. #12
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    Quote Originally Posted by jshooks View Post
    I downloaded the 4 example/testfiles, tested them to make sure they played the songs, tranferred them on a Sandisk 16 GB SD card, compiled and programmed the Frank_B_MP3_Player2 sketch on a new Teensy 3.2 and Audio Shield board. The same rapid listing in serial monitor of files being accessed, but not played. So it appears it is not the .mp3 files that is the problem. I tried this on another set of SD card (same example songs), Teensy 3.2 and Audio Shield. I don't have the 3 buttons connected on the breadboard for next, previous or pause to inputs 2, 3 and 4. But since they are pull high, I don't think that would prevent it from playing the songs. As to your comment about free RAM, since this is an un-modified sketch (except for the "user" main loop and setup at the bottom) I don't think should be a problem either. Any ideas?
    No. Maybe try the other example?
    Open Mp3FilePlayer.ino and edit the filenames.

  13. #13
    Now it works with the Mp3FilePlayer program and same songs! Not quite sure what that means as far as the more advanced Frank_B_MP3_Player2? I would prefer the latter as it has more functions like auto loading file names. I suppose I could start integrating those features into the Mp3FilePlayer and see where it starts malfunctioning. Is that your advise?

  14. #14
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    Hm, looks like we should review it.. It was a contribution by a user.

  15. #15
    Junior Member
    Join Date
    Feb 2020
    Posts
    10
    Sorry to revive an old thread, did you ever review this? I experienced the exact same issue as above. I actually spent about 2hrs trying to figure out what I'd done wrong! I Loaded up the Mp3FilePlayer.ino - mp3's playing fine now. Seems like the advanced sketch gets stuck / hangs in the "while is playing loop" - it doesn't actually seem to start playing or even get into the update controls part of the while loop. Also noticed that in the sketch (for me anyway), it is searching for ".MP3" files, it doesn't find any until I changed the search to ".mp3" - lowercase I'll try piece together (I'm a real beginner - lol) an advanced player using the 2.ino files that have been made available by Frank. Thanks Frank!!

  16. #16
    Junior Member
    Join Date
    Feb 2020
    Posts
    10
    So it seems like the advanced sketch is super picky about the file name length. The 8.3 rule still seems to stand - even now in 2021!! I changed the file names to super short (8 characters before the dot) and all is working now - Strange that the Mp3FilePlayer.ino works with long file names though... Hope this helps anyone else that gets stuck with this.

  17. #17
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    Quote Originally Posted by CrazyCraig View Post
    So it seems like the advanced sketch is super picky about the file name length. The 8.3 rule still seems to stand - even now in 2021!! I changed the file names to super short (8 characters before the dot) and all is working now - Strange that the Mp3FilePlayer.ino works with long file names though... Hope this helps anyone else that gets stuck with this.
    This should be fixed with the latest Teensyduino 1.54.
    (i hope?)

  18. #18
    Junior Member
    Join Date
    Feb 2020
    Posts
    10
    Gonna give it a try. I'll let you know the outcome.
    Thanks so much Frank.

  19. #19
    Junior Member
    Join Date
    Feb 2020
    Posts
    10
    Unfortunately, it's still the same.
    Just gets stuck on songs with long filenames.
    Also seems to be making duplicates with a ._ filename of each track on the sd card.
    So it plays one track, then tries to play the same one (with dot, underscore) again, but gets stuck there as there's no such file.
    I specifically purchased a T4 with audio board to make a kick ass mp3player, so...
    I'm a bit sad to discover the limited functionality of mp3 playback (no long names / id3 tags).
    Especially considering the T4 is not even working hard in the slightest.
    Oh well, Im sure I'll find another use for it sometime down the line.
    Thanks again for your input.
    .

  20. #20
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    Quote Originally Posted by CrazyCraig View Post
    Unfortunately, it's still the same.
    Just gets stuck on songs with long filenames.
    Also seems to be making duplicates with a ._ filename of each track on the sd card.
    So it plays one track, then tries to play the same one (with dot, underscore) again, but gets stuck there as there's no such file.
    I specifically purchased a T4 with audio board to make a kick ass mp3player, so...
    I'm a bit sad to discover the limited functionality of mp3 playback (no long names / id3 tags).
    Especially considering the T4 is not even working hard in the slightest.
    Oh well, Im sure I'll find another use for it sometime down the line.
    Thanks again for your input.
    .
    Had no time to try the sketch, but i briefly looked over it:
    char playthis[15];
    could be the problem. Perhaps try 128 instead.
    If it still not works,, I can take a look tomorrrow.

    Anyway, these are examples only. The Idea is, that you write your own code

  21. #21
    Member
    Join Date
    Aug 2018
    Location
    Brisbane, Australia
    Posts
    77
    Quote Originally Posted by Frank B View Post
    Had no time to try the sketch, but i briefly looked over it:
    char playthis[15];
    could be the problem. Perhaps try 128 instead.
    Probably better to use MAX_FILENAME_LEN which is defined in SD.h

  22. #22
    Junior Member
    Join Date
    Feb 2020
    Posts
    10
    128 made no difference either. I've been learning the code by watching videos (lots of them!!)
    and using bits of examples to piece together a functional piece of code for my purposes.
    My plan is to utilise the line input of the audio board, signal coming in from external dj mixer running through the teensy, out to a balanced op-amp circuit.
    Then have an mp3 player (which I'm working on now) with 16x2 lcd / keypad board, that I could browse the music on sd card. Select a mp3 and keep it paused as a backup.
    2 rotary pots to control each mixer gain, so if the dj software gives hassles or freezes, I quickly turn down that volume & play the backup track that was paused.
    I think I've made good progress so far, I can now mix the line input with mp3's from the sd card.
    I've been trying my best to figure out how the filenames are being delt with in this code, but this is still a bit above my level.
    I figured out that the numbers in brackets[] related to the ascii table with [15] being "shift in" and [128] being an "extended code".
    I just don't understand what relevance unusual characters like that has on the actual file names.
    I still have a lot to learn, trying to learn from watching youtube videos & playing around with the code is one way to learn,
    but it's painfully slow and always leaves the potential for learning something wrong. Most people are not willing to share their knowledge.
    So I really do appreciate your input Frank. I'll take whatever I can get.

  23. #23
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    I'll look tomorrow.

  24. #24
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,279
    Please update the example code from github - should work now

  25. #25
    Junior Member
    Join Date
    Feb 2020
    Posts
    10
    All working nicely now.
    No more problems with long file names.
    Thank you so much Frank.
    You rock!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •