void cd_play(unsigned first, unsigned last) { mciSendString("set cdaudio time format tmsf", NULL, 0, NULL); if (first == 1 && last == 1000) { mciSendString("play cdaudio", NULL, 0, NULL); return; } unsigned last_track = cd_number(); if (last > last_track) { last = last_track; } TCHAR achCommandBuff[128]; int result; MCIERROR err; // Form the command string. sprintf(achCommandBuff, "play cdaudio from %u to %u", first, last); if (result == -1) { //TODO: show error message return; } // Send the command string. err = mciSendString(achCommandBuff, NULL, 0, NULL); if (err != 0) { //TODO: show error message return; } return; }
void MidiService::play(string file, int volume) { // Предварительно закрываем предыдущий файл. // В один момент времени может проигрываться только один файл MIDI. close(true, ""); // Открываем файл. string command = "open \"" + file + "\" type sequencer alias MidiFile"; wstring wCommand = widen(command); LPCWSTR pCommand = wCommand.c_str(); MCIERROR err = mciSendString(pCommand, NULL, 0, NULL); if (err != 0) { showError("Не удалось открыть MIDI-файл: " + file); return; } // Запускаем проигрывание. err = mciSendString(L"play MidiFile from 0", NULL, 0, NULL); if (err != 0) { showError("Не удалось запустить MIDI-файл: " + file); return; } // Устанавливаем громкость проигрываемого файла. setVolume(volume); // Сохраняем имя файла. midiFile = file; }
void cd_set_position(unsigned long pos) { bool was_playing = cd_playing(); mciSendString("set cdaudio time format milliseconds", NULL, 0, NULL); mciSendString("set seek exactly on", NULL, 0, NULL); TCHAR achCommandBuff[128]; int result; MCIERROR err; // Form the command string. result = sprintf(achCommandBuff, "seek cdaudio to %u", pos); if (result == -1) { //TODO: show error message return; } // Send the command string. err = mciSendString(achCommandBuff, NULL, 0, NULL); if (err != 0) { //TODO: show error message return; } if (was_playing) { mciSendString("play cdaudio", NULL, 0, NULL); } return; }
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE; cs.style &= ~WS_BORDER; cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL); //-----------------------------------游戏数据初始化部分------------------------- //加载背景 m_bg.Load("bg.png"); //打开音乐文件 mciSendString("open background.mp3 alias bgMusic ", NULL, 0, NULL); mciSendString("play bgMusic repeat", NULL, 0, NULL); m_snow=new CParticle(100); //初始化 m_snow->Init(); return TRUE; }
void CCDA::Play( ) { char ch[64]; bWorking = false; CDA_STATE state = GetState( ); if ( (state != CDA_STATE_NOTREADY) ){ if (bPaused){ sprintf ( ch, "play cdaudio to %d", dwCurTrack + 1 ); err = mciSendString ( ch, retStr, retLen, 0 ); if ( err != 0 ){ sprintf( ch, "play cdaudio" ); err = mciSendString ( ch, retStr, retLen, 0 ); } if ( err == 0 ){ bWorking = true; bPaused = false; } return; } if ( dwCurTrack ){ lKeepTime= lTotalTime; sprintf ( ch, "play cdaudio from %d to %d", dwCurTrack, dwCurTrack + 1 ); err = mciSendString ( ch, retStr, retLen, 0 ); if ( err != 0 ){ sprintf( ch, "play cdaudio from %d", dwCurTrack ); err = mciSendString ( ch, retStr, retLen, 0 ); } if (err == 0){ lKeepTime = lTotalTime; bWorking = true; } } } }
void Audio::Create(const String& nameRef) { TCHAR buffer[100]; String sendString; if (nameRef.EndsWith(".mp3")) sendString = String("open \"") + m_FileName + "\" type mpegvideo alias " + m_Alias; else if (nameRef.EndsWith(".wav")) sendString = String("open \"") + m_FileName + "\" type waveaudio alias " + m_Alias; else if (nameRef.EndsWith(".mid")) sendString = String("open \"") + m_FileName + "\" type sequencer alias " + m_Alias; int result = mciSendString(sendString.ToTChar(), 0, 0, 0); if (result != 0) return; sendString = String("set ") + m_Alias + " time format milliseconds"; mciSendString(sendString.ToTChar(), 0, 0, 0); sendString = String("status ") + m_Alias + " length"; mciSendString(sendString.ToTChar(), buffer, 100, 0); m_Duration = String(buffer).ToInteger(); // Create a window to catch the MM_MCINOTIFY message with m_hWnd = CreateWindow(TEXT("STATIC"), TEXT(""), 0, 0, 0, 0, 0, 0, 0, GetModuleHandle(0), 0); SetWindowLong(m_hWnd, GWL_WNDPROC, (LONG) AudioProcStatic); // set the custom message loop (subclassing) SetWindowLong(m_hWnd, GWL_USERDATA, (LONG) this); // set this object as the parameter for the Proc }
void CCDA::Open( ) { Close ( ); mciSendString ( "open cdaudio shareable wait", retStr, retLen, 0 ); mciSendString ( "set cdaudio door closed", retStr, retLen, 0 ); mciSendString ( "set cdaudio time format tmsf", retStr, retLen, 0 ); mciSendString ( "set cdaudio audio_all", retStr, retLen, 0 ); }
//============================================================================= // Move to the previous track //============================================================================= MCIERROR CCDAudio::Backward() { TCHAR szBuff2[128], szBuff3[32]; int nCurrTrack = GetCurrentTrack(); const int nLastTrack = GetTracksCount(); if( (nCurrTrack == 0) || (nLastTrack == 0) || (nCurrTrack == 1) ) return 0; nCurrTrack--; _stprintf( szBuff2, _T("status cdaudio position track %d"), nCurrTrack ); m_nErrorCode = mciSendString( szBuff2, szBuff3, sizeof(szBuff3), NULL ); if( m_nErrorCode != 0 ){ MCIError( m_nErrorCode ); return m_nErrorCode; } memset(szBuff2, 0, sizeof(szBuff2)); _stprintf( szBuff2, _T("play cdaudio from %s"), szBuff3 ); m_nErrorCode = mciSendString( szBuff2, NULL, 0, NULL ); if( m_nErrorCode != 0 ){ MCIError( m_nErrorCode ); return m_nErrorCode; } return m_nErrorCode; }
void CIRC::CloseDrive(char *szDevice) { char szTemp[100]=""; sprintf(szTemp, "Open %s Alias CD%s Type CDAudio", szDevice, szDevice); mciSendString(szTemp, 0, 0, 0); sprintf(szTemp, "Set CD%s Door Closed", szDevice); mciSendString(szTemp, 0, 0, 0); }
//============================================================================= // Eject the CDROM //============================================================================= void CCDAudio::EjectCDROM() { if( IsMediaInsert() ) { m_nErrorCode = mciSendString(_T("Set CDAudio Door Open"), NULL, 0, NULL); } else { m_nErrorCode = mciSendString(_T("Set CDAudio Door Closed"), NULL, 0, NULL); } }
void CCDA::Close( ) { CDA_STATE state = GetState( ); if ( (state == CDA_STATE_PAUSE) || (state == CDA_STATE_PLAY) ){ mciSendString ( "stop cdaudio", retStr, retLen, 0 ); } mciSendString ( "close cdaudio", retStr, retLen, 0 ); lKeepTime = 0; bWorking = false; bPaused = false; }
void CSound::play_startSND(bool flag) { if(flag) { mciSendString(TEXT("open res\\music\\开始.mp3"),0,NULL,NULL); mciSendString(TEXT("play res\\music\\开始.mp3 repeat"),0,NULL,NULL); } else { mciSendString(TEXT("pause res\\music\\开始.mp3"),0,NULL,NULL); } }
//============================================================================= // Destructor //============================================================================= CCDAudio::~CCDAudio() { if( IsReady() ) { if( IsPaused() || IsPlaying() ) { mciSendString( _T("stop cdaudio"), NULL, 0, NULL ); } mciSendString( _T("close cdaudio"), NULL, 0, NULL ); } }
//=================================================* // ----------------------- Stop Playing If/When Told //===================================================* void StopFile(void) { m_bKillPCBeep = 1; StopWave(); if(m_bMCIPlaying) { mciSendString("stop myfile", NULL, 0, NULL); mciSendString("close myfile", NULL, 0, NULL); m_bMCIPlaying = FALSE; m_countPlay = 0; } g_bPlayingNonstop = 0; }
void SoundManager::Play_Bg(string path) { // mcisendstring으로 간단하게 배경음을 불러온다. string name; name = "open "; name += path; name += " type mpegvideo alias A"; mciSendString(name.c_str(), NULL, NULL, NULL); // 그리고 무한반복 재생 mciSendString("play A notify repeat", NULL, NULL, NULL); }
// Load background theme song void load_sound(){ FILE *file; if((file = fopen("bg2.mp3", "r"))==NULL){ printf("File tidak ditemukan: bg.mp3!\n"); getch(); exit(1); } else printf("Inisialisasi audio berhasil.\n"); fclose(file); strcat(cmdvol, itoa(vol, cmdvolvar, 40)); mciSendString("open bg2.mp3 type mpegvideo alias mySound", NULL, 0, 0); mciSendString("play mySound repeat", NULL, 0, 0); mciSendString(cmdvol, NULL, 0, 0); }
unsigned long cd_position() { mciSendString("set cdaudio time format milliseconds", NULL, 0, NULL); unsigned long position; MCIERROR mciError; TCHAR mciReturnBuffer[512]; mciError = mciSendString("status cdaudio position", mciReturnBuffer, sizeof(mciReturnBuffer), NULL); if (mciError != 0) { //TODO: Show error message // HRESULT_FROM_WIN32(mciError) return 0; } sscanf(mciReturnBuffer, "%d", &position); return position; }
void play_bgm(char *fname){ char s1[100] = "open "; char s2[100] = "play "; char s3[100] = " repeat"; if(music_flag){ strcat(s1,fname); mciSendString(s1, NULL, 0, NULL); strcat(s2,fname); strcat(s2,s3); mciSendString(s2, NULL, 0, NULL); }else close_bgm(fname); //add something //return NULL; }
bool __cdecl StopSound (void) { if(mciSendString("stop mydevice", NULL, 0, NULL) != 0) return false; return true; }
void AudioSystem::playEndStateMusic(void) { std::string str = Util::getSingletonPtr()->getShortPath() + "/Media/Music/EndState.mp3"; char buf[128]; mciSendString(std::string("play " + str + " repeat").c_str(), buf, sizeof(buf), NULL); }
bool __cdecl StartSound (void) { if(mciSendString("play mydevice from 0", NULL, 0, NULL) != 0) return false; return true; }
bool __stdcall CloseSound (void) { if(mciSendString("close mydevice", NULL, 0, NULL) != 0) return false; return true; }
static void test_midi_mci(HWND hwnd) { MCIERROR err; char buf[1024]; memset(buf, 0, sizeof(buf)); err = mciSendString("sysinfo sequencer quantity", buf, sizeof(buf), hwnd); ok(!err, "mci sysinfo sequencer quantity returned %d\n", err); if (!err) trace("Found %s MCI sequencer devices\n", buf); if (!strcmp(buf, "0")) return; err = mciSendString("capability sequencer can record", buf, sizeof(buf), hwnd); ok(!err, "mci sysinfo sequencer quantity returned %d\n", err); if(!err) ok(!strcmp(buf, "false"), "capability can record is %s\n", buf); }
//============================================================================= // Return the length of the given track //============================================================================= int CCDAudio::GetTrackLength(const int nTrack) { if(IsMediaInsert()) { const int nBuffSize = 64; TCHAR szTrack[10]; TCHAR szReqBuff[nBuffSize]; TCHAR szBuff[nBuffSize]; ITOA( nTrack, szTrack, 10 ); lstrcpy( szReqBuff, _T("status cdaudio length track ") ); lstrcat( szReqBuff, szTrack ); m_nErrorCode = mciSendString( szReqBuff, szBuff, nBuffSize, NULL ); if( m_nErrorCode != 0 ) { return 0; } TCHAR szMin[3], szSec[3]; STRNCPY( szMin, szBuff, 2 ); STRNCPY( szSec, (szBuff + 3), 2 ); return ((ATOI(szMin) * 60) + ATOI(szSec)); } return 0; }
void change_bgm(char *fname, char *fname2){ char s1[100] = "close "; strcat(s1, fname); mciSendString(s1, NULL, 0, NULL); if(music_flag) play_bgm(fname2); }
// Send a string to the Media Control Interface // If an error occurs, display it and the string // that produced the error. void sendCommand(char *s) { int i; i=mciSendString(s,NULL,0,0); if(i) { sprintf(msg,"Error %d when sending %s\n",i,s); MessageBox(NULL,msg,"cmdmp3win",MB_OK); } }
////////////////////////////////////////////////////////////////////////////////// // Restarts the MIDI file from the beginning. ////////////////////////////////////////////////////////////////////////////////// BOOL CDXMusic::Restart(void) { if (mciSendString("play MUSIC from 0 notify", NULL, 0, m_hWnd) != 0) { return (FALSE); } return TRUE; }
void cd_set_track_position(unsigned long pos) { mciSendString("set cdaudio time format milliseconds", NULL, 0, NULL); unsigned long position; MCIERROR mciError; TCHAR mciCommandBuffer[512]; TCHAR mciReturnBuffer[512]; sprintf(mciCommandBuffer, "status cdaudio position track %u", cd_track()); mciError = mciSendString(mciCommandBuffer, mciReturnBuffer, sizeof(mciReturnBuffer), NULL); if (mciError != 0) { //TODO: Show error message // HRESULT_FROM_WIN32(mciError) return; } sscanf(mciReturnBuffer, "%d", &position); cd_set_position(position + pos); }
////////////////////////////////////////////////////////////////////////////////// // Stops the currently playing MIDI file. ////////////////////////////////////////////////////////////////////////////////// CDXMusic::Stop() { if (mciSendString("close all", NULL, 0, NULL) != 0) { return (FALSE); } return TRUE; }
unsigned long cd_track_length(unsigned n) { mciSendString("set cdaudio time format milliseconds", NULL, 0, NULL); unsigned long length; MCIERROR mciError; TCHAR mciCommandBuffer[512]; TCHAR mciReturnBuffer[512]; sprintf(mciCommandBuffer, "status cdaudio length track %u", n); mciError = mciSendString(mciCommandBuffer, mciReturnBuffer, sizeof(mciReturnBuffer), NULL); if (mciError != 0) { //TODO: Show error message // HRESULT_FROM_WIN32(mciError) return 0; } sscanf(mciReturnBuffer, "%d", &length); return length; }