该主题前面的链接
1.开箱 https://bbs.elecfans.com/jishu_2172464_1_1.html
2.sd卡 播放 https://bbs.elecfans.com/jishu_2173612_1_1.html
3.音量记忆、播放暂停功能实现 https://bbs.elecfans.com/jishu_2183725_1_1.html
此贴主要实现sd 卡根目录wav 文件搜索 ,并实现相应的播放
- 首先要通过字符串来识别是否是wav文件
//通过后缀名识别文件类型
uint8_t tell_type(char *p)
{
int i=0;
char *attr;
while(i<200)
{
if(*p=='
')
break;
i++;
p++;
}
if(i==200)
return 1;
i=0;
while(i<5)
{
if(*p=='.')
{
p++;
attr=p;
break;
}
i++;
p--;
}
if(i==5)
return 2;
if((strcmp(attr,"WAV")==0)||(strcmp(attr,"wav")==0))
{
return 0;
}
else
{
return 4;
}
}
2.扫描所有根目录文件,并记录wav个数及相应的index
uint16_t wavGetNum(uint8_t*path)
{
DIR tdir;
uint16_t rval =0;
uint8_t* fn;
// DWORD tmp;
DWORD fileindex=0;
uint8_t res = f_opendir(&tdir, (const TCHAR*)path);
tfileinfo.fsize = 255;
if(res ==FR_OK){
//LOG_I("open root dir sucess");
while(1){
fileindex++;
// tmp = tdir.dptr;
// LOG_I("dir_ofset %d",tmp);
res = f_readdir(&tdir, &tfileinfo);
if(res!=FR_OK||tfileinfo.fname[0]==0){
//LOG_I("found the end");
break;
}
res =tell_type(tfileinfo.fname);
if(res==0){
// LOG_I("get the wav");
wavIndex[rval] = fileindex-1;//get the index
rval++;
}
}//endwhile
}
else{
LOG_I("open root dir fail");
}
return rval;
}
3.在sd 卡mount 处进行 wav文件扫描,并获取相应的wav名称
uint8_t* getFilePath(uint32_t index,uint8_t* path)
{
DIR filedir;
uint8_t *filepath =NULL;
tfileinfo.fsize = 255;
uint8_t res = f_opendir(&filedir, path);
if(res == FR_OK){
// LOG_I("dir_ofset %d",index);
f_seekdir(&filedir, index);
// LOG_I("dir_ofset %d",filedir.dptr);
res =f_readdir(&filedir, &tfileinfo);
if(res== FR_OK){
//LOG_I("get the file %s",tfileinfo.fname);
filepath = &wavFileName[0];
strcpy(filepath,&tfileinfo.fname[0]);
}
else {
LOG_I("open file name error");
}
}
else{
LOG_I("open root dir fail");
}
return filepath;
}
实际运行log
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)