MusicPlayer.getMusicName()
AudioPro.getMusicName(val)
作用
此函数可返回SD卡内对应序号音频文件的文件名
参数
val:音频文件序号
返回值
返回SD卡内对应序号音频文件的文件名
示例
#include <Microduino_AudioPro.h>
#include <SD.h>
AudioPro_FilePlayer musicPlayer = AudioPro_FilePlayer(SD);
uint8_t fileNum = 0; //文件数量
void setup() {
Serial.begin(115200);
Serial.println(F("AudioPro(VS1053) Simple Test"));
pinMode(SD_PIN_SEL, OUTPUT); //先初始化AudioPro,所以先使能SD卡
digitalWrite(SD_PIN_SEL, HIGH);
delay(500);
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
Serial.println(F("VS1053 found"));
if (!SD.begin(SD_PIN_SEL)) {
Serial.println(F("initialization failed!"));
return;
}
Serial.println(F("initialization done."));
musicPlayer.setVolume(96); //left & right 0-127
Serial.println(F("Enter Index of File to play"));
fileNum = musicPlayer.getMusicNum(); //可以获取SD卡中曲目列表以及数量
Serial.print(F("Music Files : "));
Serial.println(fileNum);
for (uint8_t a = 0; a < fileNum; a++) {
Serial.print(F("\t File["));
Serial.print(a);
Serial.print(F("]: "));
Serial.println(musicPlayer.getMusicName(a)); //在此获取对应序号歌曲的文件名
}
// If DREQ is on an interrupt pin, we can do background
musicPlayer.useInterrupt(VS1053_PIN_DREQ); // DREQ int
}
void loop() {
}
其他