bool CSoundMgr::PlayMusic (const CString &sFilename, int iPos, CString *retsError) // PlayMusic // // Starts playing the given MP3 file { try { if (m_hMusic == NULL) return false; // Figure out our current state SMusicPlayState State; GetMusicPlayState(&State); // If we're not already playing this file, open it if (!strEquals(sFilename, State.sFilename)) { // Stop playing first if (State.bPlaying || State.bPaused) MCIWndStop(m_hMusic); // Open new file if (MCIWndOpen(m_hMusic, sFilename.GetASCIIZPointer(), MCI_OPEN_SHAREABLE) != 0) { if (retsError) { char *pDest = retsError->GetWritePointer(1024); MCIWndGetError(m_hMusic, pDest, retsError->GetLength()); retsError->Truncate(lstrlen(pDest)); } return false; } } // Seek to the proper position MCIWndSeek(m_hMusic, Max(0, Min(iPos, State.iLength))); // Play it if (MCIWndPlay(m_hMusic) != 0) return false; // Done return true; } catch (...) { return false; } }
void GAME4::OnBnClickedButton2() { HWND hMCI; CString choose = _T("e:\\des\\DES\\res\\天空之城.mp3");//音乐文件的路径 hMCI = MCIWndCreate(NULL, NULL,WS_POPUP|MCIWNDF_NOPLAYBAR|MCIWNDF_NOMENU,choose); MCIWndPlay(hMCI); //播放音乐 // TODO: 在此添加控件通知处理程序代码 }
//播放Mp3音乐 HWND PlayCardMusic(TCHAR FileName[],HWND hParent) { HWND hmciwnd; //hmciwnd = MCIWndCreate(this->m_hWnd,AfxGetInstanceHandle(),WS_CHILD,FileName); hmciwnd=MCIWndCreate(hParent,AfxGetInstanceHandle(),WS_CHILD|MCIWNDF_NOMENU|MCIWNDF_NOOPEN|MCIWNDF_NOPLAYBAR|MCIWNDF_NOERRORDLG,FileName); if(hmciwnd) MCIWndPlay(hmciwnd); return hmciwnd; }
void CSoundMgr::TogglePlayPaused (void) // TogglePlayPaused // // Play/Pause { int iMode = MCIWndGetMode(m_hMusic, 0, NULL); if (iMode == MCI_MODE_PLAY) MCIWndPause(m_hMusic); else if (iMode == MCI_MODE_PAUSE) MCIWndPlay(m_hMusic); }
void CServerConnect::StartShowLogoAVI() { if( m_hWndAVI ) return; /* m_hWndAVI = MCIWndCreate( _g_hWnd, g_hInst, MCIWNDF_NOERRORDLG|MCIWNDF_NOMENU|MCIWNDF_NOOPEN|MCIWNDF_NOPLAYBAR |MCIWNDF_NOTIFYMODE|MCIWNDF_NOTIFYERROR, "D:/¹¬Çâ/°³¹ß/CWorking/logo.avi" ); */ if( m_hWndAVI ) { MCIWndPlay(m_hWndAVI); m_bShowingLogoAVI = TRUE; MAINGAME->PauseRender( TRUE ); } }
BOOL MP3::Play(CString &strPath) { m_hVideo = NULL; if(m_hVideo == NULL) { m_hVideo = MCIWndCreate(AfxGetMainWnd()->GetSafeHwnd(), AfxGetInstanceHandle(), WS_CHILD |MCIWNDF_NOMENU,strPath); } else { MCIWndHome(m_hVideo); } MCIWndPlay(m_hVideo); m_bPause = FALSE; return TRUE; }
void MCIOBJ::work(void) { // InvalidateRect(displayWnd,NULL,FALSE); if (GLOBAL.fly) return; if (!m_video) return; if (MCIWndGetPosition(m_video)==MCIWndGetLength(m_video)) playing=FALSE; if ((play!=INVALID_VALUE) && (m_video) && (!playing)) { if ((!play_once)||(resetted)) { MCIWndPlay(m_video); playing = TRUE; } resetted=FALSE; } if (play==INVALID_VALUE) { resetted=TRUE; if ((m_video) && (playing)) { MCIWndStop(m_video); playing=FALSE; } } acttime=TIMING.acttime-prevtime; if (((float)acttime/(float)TIMING.pcfreq*1000)>(float)upd_speed) { prevtime=TIMING.acttime; if (actspeed!=speed) { actspeed=speed; MCIWndSetSpeed(m_video, speed); } if (actvolume!=volume) { actvolume=volume; MCIWndSetVolume(m_video, volume); } if (step) { MCIWndStep(m_video,step); step=0;} if (pos_change) {MCIWndSeek(m_video,pos_center+pos_change); pos_change=0;} if (MCIWndGetPosition(m_video)==MCIWndGetLength(m_video)) { //MCIWndPlay(m_video); MCIWndSeek(m_video,1); } } }
static javacall_result audio_start(javacall_handle handle){ audio_handle* pHandle = (audio_handle*)handle; if (JAVACALL_FALSE == pHandle->isForeground) { JAVA_DEBUG_PRINT("[jc_media] Audio fake start in background!\n"); return JAVACALL_OK; } /* Create MCI window by using temp file */ audio_prepare_MCIWnd(pHandle); JAVA_DEBUG_PRINT1("[jc_media] + javacall_media_start %s\n", pHandle->fileName); /* Seek to play position */ if (pHandle->offset) { MCIWndSeek(pHandle->hWnd, pHandle->offset); pHandle->curTime = pHandle->offset; } else { pHandle->curTime = 0; } /* Start play */ if (pHandle->hWnd && 0 == MCIWndPlay(pHandle->hWnd)) { JAVA_DEBUG_PRINT("[jc_media] - javacall_media_start OK\n"); pHandle->duration = MCIWndGetLength(pHandle->hWnd); javanotify_on_media_notification(JAVACALL_EVENT_MEDIA_DURATION_UPDATED, pHandle->playerId, (void*)pHandle->duration); pHandle->timerId = (UINT)timeSetEvent(TIMER_CALLBACK_DURATION, 100, audio_timer_callback,(DWORD)pHandle, TIME_PERIODIC); return JAVACALL_OK; } return JAVACALL_FAIL; }
LRESULT CALLBACK MCIDlgHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { char szFileName[MAX_PATH]; MCIOBJ * st; st = (MCIOBJ *) actobject; if ((st==NULL)||(st->type!=OB_MCIPLAYER)) return(FALSE); switch( message ) { case WM_INITDIALOG: SetDlgItemText(hDlg, IDC_MCIFILE, st->mcifile); SCROLLINFO lpsi; lpsi.cbSize=sizeof(SCROLLINFO); lpsi.fMask=SIF_RANGE|SIF_POS; lpsi.nMin=4; lpsi.nMax=5000; SetScrollInfo(GetDlgItem(hDlg,IDC_SPEEDUPDATEBAR),SB_CTL,&lpsi, TRUE); SetScrollPos(GetDlgItem(hDlg,IDC_SPEEDUPDATEBAR), SB_CTL,st->upd_speed, TRUE); SetDlgItemInt(hDlg, IDC_UPDATESPEED, st->upd_speed, FALSE); SetDlgItemInt(hDlg, IDC_POS_CENTER, st->pos_center, FALSE); CheckDlgButton(hDlg, IDC_PLAY_ONCE, st->play_once); return TRUE; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_OPEN: if (!(strcmp(st->mcifile,"none"))) { strcpy(szFileName,GLOBAL.resourcepath); strcat(szFileName,"MOVIES\\*.avi"); } else strcpy (szFileName,st->mcifile); if (open_file_dlg(hDlg, szFileName, FT_AVI, OPEN_LOAD)) { st->playing=FALSE; strcpy(st->mcifile,szFileName); SetDlgItemText(hDlg, IDC_MCIFILE, st->mcifile); } InvalidateRect(hDlg,NULL,FALSE); break; case IDC_PLAY_ONCE: st->play_once=IsDlgButtonChecked(hDlg,IDC_PLAY_ONCE); break; case IDC_LOAD: if (st->m_video) { MCIWndStop(st->m_video); MCIWndDestroy(st->m_video); } st->m_video = MCIWndCreate(ghWndMain, hInst,WS_VISIBLE|WS_THICKFRAME|MCIWNDF_NOERRORDLG,st->mcifile); if (!st->m_video) report_error ("Cannot open MCI File"); else { RECT prc; MCIWndSetZoom(st->m_video,100); MCIWndGetSource(st->m_video,&prc); MCIWndSetTimeFormat(st->m_video ,"ms"); MCIWndSetActiveTimer(st->m_video,500); if ((!strstr(st->mcifile,".mp3")) && (!strstr(st->mcifile,".wav"))) SetWindowPos(st->m_video,HWND_TOPMOST,st->left,st->top,st->left+prc.right-prc.left,st->top+prc.bottom-prc.top,SWP_SHOWWINDOW); else ShowWindow(st->m_video,FALSE); } break; case IDC_MCIPLAY: if (st->m_video) { MCIWndSetSpeed(st->m_video,st->speed); MCIWndPlay(st->m_video); st->playing=TRUE; } break; case IDC_MCISTOP: if (st->m_video) { MCIWndStop(st->m_video);} // MCIWndDestroy(st->m_video); } st->playing=FALSE; break; case IDC_MCIPLUS: st->speed+=50; if (st->m_video) { MCIWndSetSpeed(st->m_video,st->speed); //MCIWndStep(st->m_video,2); MCIWndPlay(st->m_video); } break; case IDC_MCIMINUS: st->speed-=50; if (st->m_video) { MCIWndSetSpeed(st->m_video,st->speed); //MCIWndStep(st->m_video,2); MCIWndPlay(st->m_video); } break; case IDC_POS_CENTER: st->pos_center=GetDlgItemInt(hDlg,IDC_POS_CENTER,0,FALSE); break; } break; case WM_HSCROLL: { int nNewPos; nNewPos = get_scrollpos(wParam,lParam); if (lParam == (long) GetDlgItem(hDlg,IDC_SPEEDUPDATEBAR)) { SetDlgItemInt(hDlg, IDC_UPDATESPEED, nNewPos, TRUE); st->upd_speed=nNewPos; } break; } case WM_SIZE: case WM_MOVE: update_toolbox_position(hDlg); break; } return FALSE; }