예제 #1
0
파일: Sound.cpp 프로젝트: bmer/Alchemy
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;
		}
	}
예제 #2
0
void CMCIWndDemoView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	const CString &filename = GetDocument()->GetPathName();
	
	if(!m_hMCIWnd)
	{
		m_hMCIWnd = MCIWndCreate(m_hWnd, 
			AfxGetInstanceHandle(),
			MCIWNDF_NOTIFYSIZE | MCIWNDF_NOERRORDLG | WS_CHILD | WS_VISIBLE,
			NULL);
	}
	
	if(m_hMCIWnd)
	{
		if(!filename.IsEmpty())
		{
			MCIWndOpen(m_hMCIWnd, (LPCSTR)filename, 0);
		}
	}
}
예제 #3
0
bool CSoundMgr::CanPlayMusic (const CString &sFilename)

//	CanPlayMusic
//
//	Returns TRUE if we can play the music

	{
	if (m_hMusic == NULL)
		return false;

	//	Open the device

	if (MCIWndOpen(m_hMusic, sFilename.GetASCIIZPointer(), 0) != 0)
		return false;

	//	Can play it?

	if (!MCIWndCanPlay(m_hMusic))
		return false;

	//	Done

	return true;
	}