www.pudn.com > RecDemo.rar > MultiPlay.cpp


// MultiPlay.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "RecDemo.h" 
#include "MultiPlay.h" 
 
#include "io.h" 
 
#include "d080d32.h" 
#include "Conf95.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMultiPlay dialog 
 
 
CMultiPlay::CMultiPlay(CWnd* pParent /*=NULL*/) 
	: CDialog(CMultiPlay::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CMultiPlay) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CMultiPlay::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CMultiPlay) 
	DDX_Control(pDX, IDC_LIST3, m_FileList2); 
	DDX_Control(pDX, IDC_LIST1, m_FileList1); 
	DDX_Control(pDX, IDC_EDIT2, m_EditTextChnl2); 
	DDX_Control(pDX, IDC_EDIT1, m_EditTextChnl1); 
	DDX_Control(pDX, IDC_BUTTON2, m_PlayButton2); 
	DDX_Control(pDX, IDC_BUTTON1, m_PlayButton1); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CMultiPlay, CDialog) 
	//{{AFX_MSG_MAP(CMultiPlay) 
	ON_WM_DESTROY() 
	ON_WM_TIMER() 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2) 
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3) 
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMultiPlay message handlers 
static	bool	PlayFlag[D080D_MAX_CONF_CHNL]; 
 
BOOL CMultiPlay::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	int		i; 
 
	for ( i = 0; i < D080D_MAX_CONF_CHNL; i ++ ) 
		PlayFlag[i] = false; 
	 
	m_EditTextChnl1.SetWindowText ( "1" ); 
	m_EditTextChnl2.SetWindowText ( "2" ); 
 
	// chnl 0 start listen conference 
	int r = AddListenChnl ( D080D_CONF_GROUP_ID, 0 );		// chnl 0 listen 
	// 
 
	SetTimer ( 2001, 100, NULL ); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CMultiPlay::OnDestroy()  
{ 
	CDialog::OnDestroy(); 
	 
	// TODO: Add your message handler code here 
	for ( int i = 0; i < D080D_MAX_CONF_CHNL; i ++ ) 
		D080D_Extra_StopPlayFile ( i ); 
 
	// chnl 0 stop listen 
	int r = SubListenChnl ( D080D_CONF_GROUP_ID, 0 );		// chnl 0 clear listen 
} 
 
void CMultiPlay::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	int	id; 
 
	id = 0; 
	if ( PlayFlag[id] ) 
	{ 
		if ( D080D_Extra_CheckPlayEnd (id) ) 
		{ 
			OnButton1(); 
		} 
	} 
	 
	id = 1; 
	if ( PlayFlag[id] ) 
	{ 
		if ( D080D_Extra_CheckPlayEnd (id) ) { 
			OnButton2(); 
		} 
	} 
 
	CDialog::OnTimer(nIDEvent); 
} 
 
long	CalculateBytes( long lStartMilSecond ); 
 
void	MultiHandlePlay ( int id, CButton *pPlayButton,  CListBox *pFileList ) 
{ 
	int		Index; 
	char	NowFileName[80]; 
 
	if ( PlayFlag[id] == false ) 
	{	// start play 
		Index = pFileList->GetCurSel(); 
		pFileList->GetText ( Index, NowFileName ); 
 
		D080D_Extra_StartPlayFile ( id, NowFileName, CalculateBytes(0), -6 ); 
 
		pPlayButton->SetWindowText ( "Stop" ); 
		PlayFlag[id] = true; 
	} 
	else {		// stop play 
		D080D_Extra_StopPlayFile ( id ); 
 
		pPlayButton->SetWindowText ( "Start" ); 
		PlayFlag[id] = false; 
	} 
} 
 
void CMultiPlay::OnButton1()  
{ 
	// TODO: Add your control notification handler code here 
	MultiHandlePlay ( 0, &m_PlayButton1, &m_FileList1 );		// multi play id = 0 
} 
 
void CMultiPlay::OnButton2()  
{ 
	// TODO: Add your control notification handler code here 
	MultiHandlePlay ( 1, &m_PlayButton2, &m_FileList2 );		// multi play id = 1 
} 
 
void	ListMatchFiles ( CListBox *pFileList, char *sss ) 
{ 
	_finddata_t fileinfo; 
	long	FindHandle, l; 
	static	int	count = 0; 
	char	TmpStr[20]; 
	int		Chnl; 
 
	Chnl = atoi ( sss ); 
	sprintf ( TmpStr, ".\\*.%d.pcm", Chnl ); 
 
	pFileList->ResetContent(); 
 
	l = FindHandle = _findfirst ( TmpStr, &fileinfo ); 
	while ( l != -1 ) { 
		pFileList->AddString ( fileinfo.name ); 
		l = _findnext ( FindHandle, &fileinfo ); 
	} 
 
	pFileList->SetCurSel ( 0 ); 
} 
 
void CMultiPlay::OnButton3()  
{ 
	// TODO: Add your control notification handler code here 
	char	TmpStr[20]; 
	 
	m_EditTextChnl1.GetWindowText ( TmpStr, 5 ); 
	ListMatchFiles ( &m_FileList1, TmpStr ); 
} 
 
void CMultiPlay::OnButton4()  
{ 
	// TODO: Add your control notification handler code here 
	char	TmpStr[20]; 
	 
	m_EditTextChnl2.GetWindowText ( TmpStr, 5 ); 
	ListMatchFiles ( &m_FileList2, TmpStr ); 
}