2017-07-27 114 views
2

我試圖使用PlaySound,我把的#pragma評論(LIB,「WINMM.LIB」)不工作

#include <windows.h> 
#include <mmsystem.h> 
#pragma comment(lib, "Winmm.lib") 
using namespace std; 

int main() 
{ 

PlaySound(L"C:\\Users\\iD Student\\Downloads\\HarryPotter.mp3", 0, SND_FILENAME); 

} 

,而不是和玩我想它的聲音,它打出了一些默認的Windows聲音。

+1

你確定那是播放聲音的方式嗎?您實際上不會[調用函數](https://msdn.microsoft.com/en-us/library/windows/desktop/dd743680%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396)在這個代碼中。 – tadman

+0

這就是我放在我的代碼頂部。實際的代碼是PlaySound行 –

+1

請發佈*實際代碼*然後編輯您的問題。 – tadman

回答

0

PlaySound不支持.mp3文件。它只支持.wav文件。

用於播放簡單的代碼的聲音:

#include <windows.h> 
#include <mmsystem.h> 
#pragma comment(lib, "Winmm.lib") 
using namespace std; 

int main() 
{ 
//Replace C:\\Users\\iD Student\\Downloads\\HarryPotter.wav with the location of your file 
PlaySound(L"C:\\Users\\iD Student\\Downloads\\HarryPotter.wav", 0, SND_FILENAME); 

}