/** 
 * \file Media.h
 * \brief Header file containing CMedia class - encapsulation class for DirectShow. It manages graphBuilder
 * for playing mp3 and avi files. Providing user simple 'Init and Play' interface.
 * 
 * \author Petar Bajic, MPE (C) All Rights Reserved, Homepage: www.mystic-peanut.com
 * \date January, 16 2007.
 */

#include "Dshow.h"

#ifndef MPE_MEDIA
#define MPE_MEDIA

/**
 * \brief CMedia class is used for playing mp3 music and avi files.
 *
 * It uses DirectShow GraphBuilder for playing media files. 
 * One instance of this class is made for each media file to be played.
 * \author Petar Bajic \date January, 16 2007.
 */
class CMedia
{
public:
	CMedia();
	~CMedia();
	bool Init(HWND hWnd, LPCWSTR filename);
	bool Play();
	bool Pause();
	bool Stop();
	void SetLoop();
	void OnGraphEvent();

	//Direct Show: Mp3 Music and Video playback
	IGraphBuilder *m_graphBuilder;
	IMediaControl *m_mediaControl;
	IMediaSeeking *m_mediaSeeking;
	IMediaEvent   *m_mediaEvent;

	LONGLONG m_begin;
	bool	m_Paused;
	bool	m_Looping;
};

#ifndef SAFE_DELETE
#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
#endif    
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
#endif    
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
#endif
#ifndef V
#define V(x)           { hr = x; }
#endif
#ifndef V_RETURN
#define V_RETURN(x)    { hr = x; if( FAILED(hr) ) { return hr; } }
#endif

#endif //MPE_MEDIA
