0
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);

    }
}

my loading function

 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);
    }
}

When I call the loading function, a file not found error occurs.

void MusicPlayer::play(int _type) {
    pFmod->update();
    result = pFmod->playSound(music[_type], NULL, false, &ch[_type]);
    errorCheck(result);
}

When I call the play function, an invalid pointer error occurs.

What is problem?

ps. my source code can play a song when its file name is composed english.

what should I do?

mela la
  • 1
  • 1
  • 1
    Have you debugged or used printf to check if MusicBox::getInstance()->container()->getSong(i)->path yields valid filepaths? – AndreLDM Mar 16 '17 at 12:55
  • AndreLDM//yes, it's valid file path. d:\\mp3\\filename.mp3 – mela la Mar 17 '17 at 02:14
  • I'm confused, which is the loading function? The one called loading() or the one indicated? –  Mar 17 '17 at 06:58
  • void MusicPlayer::loading() is loading function. – mela la Mar 17 '17 at 07:07
  • @melala You say the code plays songs with ascii-only paths, only non-ascii characters causes the error, is that right? I had to convert UTF-8 string to wchar on Windows, see if this [code](https://github.com/andreldm/kissplayer/blob/b74628b1a40000171aa6d5a9bb3dd261f708e943/src/sound.cpp#L20) helps you. – AndreLDM Mar 19 '17 at 19:47

0 Answers0