Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

A Basic Media Player

, 10 Jan 2013
Using MCIWnd wrapper class to write a simple media player
// Player.cpp: implementation of the CPlayer class.
//
//////////////////////////////////////////////////////////////////////


#include "stdafx.h"
#include "Player.h"
#include "vfw.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPlayer::CPlayer(HWND hwParent)
{
	hwndParent=hwParent;

	m_sPath="";
	c_Player=NULL;
}

CPlayer::CPlayer()
{
	hwndParent=NULL;

	m_sPath="";
	c_Player=NULL;
}

CPlayer::~CPlayer()
{
	MCIWndDestroy(c_Player);
	c_Player=NULL;
	m_sPath="";
}

void CPlayer::SetPath(CString sPath)
{
	m_sPath.Format("%s",sPath);
}

CString CPlayer::GetPath()
{
	return m_sPath;
}

void CPlayer::Play()
{
	c_Player=MCIWndCreate(hwndParent,AfxGetInstanceHandle(),
		WS_CHILD | WS_VISIBLE| MCIWNDF_NOMENU,
		m_sPath);

	MCIWndPlay(c_Player);
}

void CPlayer::Stop()
{
	MCIWndStop(c_Player);
	MCIWndDestroy(c_Player);
}

void CPlayer::Pause()
{
	MCIWndPause(c_Player);
}

void CPlayer::Resume()
{
	MCIWndResume(c_Player);
}

CString CPlayer::GetMode()
{
	char* lp=new char[3];
	CString x;
	
	MCIWndGetMode(c_Player,lp,sizeof(lp));

	x=(char*) lp;
	delete [] lp;
	return x;
}

void CPlayer::Loop()
{
	CString x;
	c_Player=MCIWndCreate(hwndParent,AfxGetInstanceHandle(),
		WS_CHILD | WS_VISIBLE|MCIWNDF_NOMENU,
		m_sPath);

	MCIWndPlay(c_Player);
	while()
	{
		x=GetMode();
		if (x!="pla")
		{
			MCIWndDestroy(c_Player);
		}
	}
}

void CPlayer::Break()
{

}

void CPlayer::SetParent(HWND hParent)
{
	hwndParent=hParent;
}

HWND CPlayer::GetParent()
{
	return hwndParent;
}

void CPlayer::SetPath(CString sPath)
{
	m_sPath.Format("%s",sPath);
}

CString CPlayer::GetPath()
{
	return m_sPath;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

M. Bonvari
Other
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 10 Jan 2013
Article Copyright 2003 by M. Bonvari
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid