Adafruit Music Maker MP3 Shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Woodyguitary
 
Posts: 2
Joined: Sun Aug 28, 2022 4:03 pm

Adafruit Music Maker MP3 Shield

Post by Woodyguitary »

Hi there,
absolute newbie here, so sorry in advance.

Project: Play random songs (file structure: 1.mp3, 2.mp2, ..., 328.mp3) from SD card when some sensor is being triggered.

I worked out how to gerenate a random file name.
But when inserting it in "musicPlayer.playFullFile() nothing happens.
Ive been working on this issue for hours now and I cant seem to figure it out.
I appreciate any help!

My Code:

Code: Select all

itoa(random(1, 329), voiceline, 10);
  strcat(voiceline, ".mp3");
    Serial.print(F("Playing   "));
    Serial.println(voiceline);
    musicPlayer.playFullFile(voiceline);
The serial monitor will display the file names as intended, but no sound whatsoever.

Ive also tried different versions of whats in the () like:

Code: Select all

musicPlayer.playFullFile("/voiceline")
or

Code: Select all

musicPlayer.playFullFile("/'voiceline'")
but nothing works.

Looking forward to help. Many thanks!!!

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit Music Maker MP3 Shield

Post by adafruit_support_mike »

You shouldn't need an initial slash.

Try stepping back to one of the example sketches that come with the Music Maker library. Can you play a single file with that?

User avatar
Woodyguitary
 
Posts: 2
Joined: Sun Aug 28, 2022 4:03 pm

Re: Adafruit Music Maker MP3 Shield

Post by Woodyguitary »

I figured it out.

letting the music play with

Code: Select all

musicPlayer.playFullFile(voiceline);
is working fine.
However, something seemed to be wrong with the created file names.
Its working with

Code: Select all

sprintf(voiceline, "%02d.mp3", random(1,329));
However, I would appreciate it, if someone could explain to me, why this works, and the other approach doesnt.

Thanks!
Hope that helps anyone else also.

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit Music Maker MP3 Shield

Post by adafruit_support_mike »

Try printing the filenames your random routine generates. You may be getting something unexpected.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”