如何在C ++中播放歌曲

问题描述:

我试图用c ++播放歌曲。我尝试使用winmm lib,它工作正常。我现在的目标是通过创建某种歌曲播放列表并将它们存储在一个阵列中来播放多首歌曲。我试了但是playound功能一直让我看错。任何人都可以告诉我如何做到这一点?



**我得到的错误与playound函数中的文字有关,显示

** LsongList未定义**





I was trying to play songs in c++. I tried using the winmm lib and it worked fine. My goal now is to play multiple songs by creating some sort of song playlist and storing them in an array. I tried it but the playsound function keeps showing me errors. Can anyone advise me how i can do that?

**The error that i get is related to the text in the playsound function which shows
**LsongList is undefined**


#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
#include <mmsystem.h>
using namespace std;

int main()

{

  string songlist[3];
  songlist[0] = "a.wav";
  songlist[1] = "b.wav";
  songlist[2] = "c.wav";
  
for(int i =0; i<3; i++)
{
PlaySound(TEXT(songlist[i]), NULL, SND_ASYNC | SND_NODEFAULT );	



}

system("pause");



}

我没有发言人来测试它现在,但它编译并运行没有错误。





I don't have speakers to test it now, but it compiles and runs without errors.


void run()
{
	LPCWSTR songlist[3] = 
	{
		TEXT("C:\\sounds\\APPLAUSE.wav"),
		TEXT("C:\\sounds\\ARROW.wav"),
		TEXT("C:\\sounds\\BOMB.wav")
	};

	for(int i =0; i<3; i++)
	{
		PlaySound(songlist[i], NULL, SND_ASYNC | SND_NODEFAULT );	
	}

}


int _tmain(int argc, _TCHAR* argv[])
{
	run();
	system("pause");
	return 0;
}