About the following code, it is written by MFC, but in test time, i run the simple program, i will not got a normal case, the program will return a failed message to me, the message is "Can't play file:[PATH]".
but if me fixed the File (not select form the the dialog), it is work, i can not find out the problem, i hope some people can help me to fix..
please excuse my poor English. thanks a lot..
About the code:
// Check Bass Version
if (HIWORD(BASS_GetVersion()) != BASSVERSION) {
this->MessageBox(_T("An incorrect version of BASS.DLL was loaded"), _T("Error!"), MB_ICONSTOP | MB_OK);
return;
}
// Start Bass
if (!BASS_Init(-1, 44100, 0, NULL, NULL)) {
this->MessageBox(_T("Can't initialize device"), _T("Error!"), MB_ICONSTOP | MB_OK);
return;
}
CString filePath = _T("");
CFileDialog dialog(true, _T("mp3"), _T("*.mp3"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER, _T("*.*|All File|*.mp3|MP3 File||"), NULL);
if (dialog.DoModal() == IDOK) {
filePath = dialog.GetPathName();
}
if (filePath == "") {
this->MessageBox(_T("Please select file first"), _T("Error!"), MB_ICONSTOP | MB_OK);
return;
}
//char * filePathChar = (char *) (LPCTSTR) filePath;
DWORD channel;
if (!(channel = BASS_StreamCreateFile(false, filePath, 0, 0, 0))
&& !(channel = BASS_MusicLoad(false, filePath, 0, 0, BASS_MUSIC_RAMPS | BASS_MUSIC_POSRESET | BASS_MUSIC_PRESCAN, 0))) {
this->MessageBox(_T("Can't play file:\n" + filePath), _T("Error!"), MB_ICONSTOP | MB_OK);
BASS_Free();
return;
}
BASS_ChannelPlay(channel,false);
About the BASS_StreamCreateFile (bass.dll):
HSTREAM BASS_StreamCreateFile(
BOOL mem,
void *file,
QWORD offset,
QWORD length,
DWORD flags
);
About the BASS_MusicLoad (bass.dll):
HMUSIC BASS_MusicLoad(
BOOL mem,
void *file,
QWORD offset,
DWORD length,
DWORD flags,
DWORD freq
);