Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Mmsystem.h"
- #pragma comment(lib,"Winmm.lib")
- enum cSoundDefintions
- {
- CSOUND_SUCCESS,
- ERR_INVALID_FILETYPE,
- ERR_PLAY_WAV,
- ERR_INVALID_COMMAND,
- CSOUND_PLAY,
- CSOUND_STOP,
- CSOUND_FILE
- };
- class cSound
- {
- char PathToFile[MAX_PATH];
- char tFile[MAX_PATH];
- char * s8_Buf;
- public:
- cSound(char*);
- DWORD Command(cSoundDefintions, char*);
- };
- cSound::cSound(char * FilePath)
- {
- strcpy(PathToFile, FilePath);
- }
- DWORD cSound::Command(cSoundDefintions command, char * FilePath = "placeholder")
- {
- switch(command)
- {
- case CSOUND_FILE:
- {
- Command(CSOUND_STOP);
- strcpy(PathToFile, FilePath);
- return CSOUND_SUCCESS;
- }
- break;
- case CSOUND_PLAY:
- {
- if(strcmp(FilePath, "placeholder") == 0)
- strcpy(tFile, PathToFile);
- if(strcmp(FilePath, "placeholder") != 0)
- strcpy(tFile, FilePath);
- DWORD u32_Attr = GetFileAttributes(tFile);
- if (u32_Attr == 0xFFFFFFFF || (u32_Attr & FILE_ATTRIBUTE_DIRECTORY))
- return ERROR_FILE_NOT_FOUND;
- char *p_s8Ext = strrchr(tFile, '.');
- s8_Buf = new char[300];
- if (stricmp(p_s8Ext, ".wav") == 0)
- {
- Command(CSOUND_STOP);
- if (!PlaySound(tFile, 0, SND_FILENAME | SND_ASYNC))
- return ERR_PLAY_WAV;
- return CSOUND_SUCCESS;
- }
- DWORD u32_Err;
- if (stricmp(p_s8Ext, ".mp3") == 0)
- {
- Command(CSOUND_STOP);
- if (strcmp("", tFile) != 0)
- {
- mciSendString("close all", 0, 0, 0);
- sprintf(s8_Buf, "open \"%s\" type mpegvideo alias MidiDemo", tFile);
- if (u32_Err = mciSendString(s8_Buf, 0, 0, 0))
- {
- delete [] s8_Buf;
- return u32_Err;
- }
- delete [] s8_Buf;
- }
- if (u32_Err = mciSendString("play MidiDemo from 0", 0, 0, 0))
- {
- if (u32_Err == 2)
- u32_Err = MCIERR_SEQ_NOMIDIPRESENT;
- return u32_Err;
- }
- return CSOUND_SUCCESS;
- }
- if (!stricmp(p_s8Ext, ".mid") || !stricmp(p_s8Ext, ".midi") || !stricmp(p_s8Ext, ".rmi"))
- {
- Command(CSOUND_STOP);
- if (strcmp("", tFile) != 0)
- {
- mciSendString("close all", 0, 0, 0);
- sprintf(s8_Buf, "open \"%s\" type sequencer alias MidiDemo", tFile);
- if (u32_Err = mciSendString(s8_Buf, 0, 0, 0))
- {
- delete [] s8_Buf;
- return u32_Err;
- }
- delete [] s8_Buf;
- }
- if (u32_Err = mciSendString("play MidiDemo from 0", 0, 0, 0))
- {
- if (u32_Err == 2)
- u32_Err = MCIERR_SEQ_NOMIDIPRESENT;
- return u32_Err;
- }
- return CSOUND_SUCCESS;
- }
- return ERR_INVALID_FILETYPE;
- }
- break;
- case CSOUND_STOP:
- {
- PlaySound(0, 0, SND_PURGE);
- mciSendString("stop MidiDemo", 0, 0, 0);
- return CSOUND_SUCCESS;
- }
- break;
- default:
- return ERR_INVALID_COMMAND;
- }
- }
Add Comment
Please, Sign In to add comment