void MusicContainer::fillMusicList() {
long h_file;
char search_Path[500];
_finddata_t file_search;
char _path[500] = "D:\\mp3";
sprintf_s(search_Path, "%s\\*.mp3", _path);
if ((h_file = _findfirst(search_Path, &file_search)) == -1L) {
printf("No files in current directory!\n");
}
else {
do {
printf("%\n", file_search.name);
MusicFile* musicFile;
musicFile = new MusicFile;
strcpy_s(musicFile->name, sizeof(musicFile->name), file_search.name);
strcpy_s(musicFile->path, sizeof(musicFile->path), _path);
strcat_s(musicFile->path, sizeof(musicFile->path), "\\");
strcat_s(musicFile->path, sizeof(musicFile->path), file_search.name);
musicList.push_back(musicFile);
} while (_findnext(h_file, &file_search) == 0);
_findclose(h_file);
}
}
我的加载功能
void MusicPlayer::loading() {
for (int i = 0; i < musicCount; i++) {
result = pFmod->createSound(MusicBox::getInstance()->container()->getSong(i)->path, FMOD_DEFAULT, NULL, &music[i]);
errorCheck(result);
}
}
当我调用加载函数时,会发现找不到文件错误。
void MusicPlayer::play(int _type) {
pFmod->update();
result = pFmod->playSound(music[_type], NULL, false, &ch[_type]);
errorCheck(result);
}
当我调用play函数时,会发生无效指针错误。
什么是问题?
PS。我的源代码可以在其文件名由英文组成时播放。
我该怎么办?