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?

5
  • 1
    Have you debugged or used printf to check if MusicBox::getInstance()->container()->getSong(i)->path yields valid filepaths? Commented Mar 16, 2017 at 12:55
  • AndreLDM//yes, it's valid file path. d:\\mp3\\filename.mp3 Commented Mar 17, 2017 at 2:14
  • I'm confused, which is the loading function? The one called loading() or the one indicated? Commented Mar 17, 2017 at 6:58
  • void MusicPlayer::loading() is loading function. Commented Mar 17, 2017 at 7: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 helps you. Commented Mar 19, 2017 at 19:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.