如何让c++编的程序和mp3类声音链接,比如下面的程序如何让mp3格式的声音发出来
Animal.h文件
class Animal
{
public:
virtual void howl()=0
};
class DomesticAnimal : public Animal
{
public:
virtual void howl()=0;
};
class Cat : public DomesticAnimal//猫
{
public:
void howl();
};
class Dog : public DomesticAnimal//狗
{
public:
void howl();
};
class Pig : public DomesticAnimal//猪
{
public:
void howl();
};
Animal.cpp文件
#include "Animal.h"
#include "PlayWave.h"
#include <iostream>
using namespace std;
void Cat::howl()
{
cout<<"猫叫!"<<endl;
PlayWave pw("E:\\C++练习\\animals\\animal sound\\cat.wav");//文件的路径
pw.play();
}
void Dog::howl()
{
cout<<"狗叫!"<<endl;
PlayWave pw("E:\\C++练习\\animals\\animal sound\\dog.wav");
pw.play();
}
void Pig::howl()
{
cout<<"猪叫!"<<endl;
PlayWave pw("E:\\C++练习\\animals\\animal sound\\pig.wav");
pw.play();
}
PlayWave.h文件
class PlayWave
{
char filename[128];
char filepath[128];
public:
PlayWave(const char*);
void setFile(const char*);
void play();
};
PlayWave.cpp文件
//#pragma comment(lib, "dsound.lib")
//#pragma comment(lib, "dxguid.lib")
#include "windows.h"
#include "mmsystem.h"
#include "PlayWave.h"
#include <cstring>
//using namespace std;
PlayWave::PlayWave(const char* filename)
{
//CFile cf;
strcpy(this->filename,filename);
}
void PlayWave::setFile(const char* filename)
{
strcpy(this->filename,filename);
}
void PlayWave::play()
{
MCI_OPEN_PARMS OpenParms;
OpenParms.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_WAVEFORM_AUDIO;//WAVE类型
OpenParms.lpstrElementName = (LPCSTR) filename;//打开的声音文件名;
OpenParms.wDeviceID = 0;//打开的音频设备的ID
mciSendCommand (NULL, MCI_OPEN,MCI_WAIT | MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT, (DWORD)(LPVOID) &OpenParms);
MCI_PLAY_PARMS PlayParms;
PlayParms.dwFrom = 0;
mciSendCommand (OpenParms.wDeviceID,MCI_PLAY,MCI_WAIT,(DWORD)(LPVOID)&PlayParms);
mciSendCommand (OpenParms.wDeviceID,MCI_CLOSE,NULL,NULL);
}
主程序.cpp
#include "Animal.h"
void makeHowl(Animal* am)
{
am->howl();
}
void main()
{
Animal* am;//创建指向Animal类对象的指针
am=new Cat();
//am->howl();
delete am;
am=new Dog();
am->howl();
delete am;
}
我想链接播放mp3格式文件,各位高手请指导一下
[此贴子已经被作者于2007-10-4 10:47:10编辑过]