⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleplayerdlg.cpp

📁 windows ce 下的自制播放器
💻 CPP
字号:
// SimplePlayerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SimplePlayer.h"
#include "SimplePlayerDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSimplePlayerDlg dialog

CSimplePlayerDlg::CSimplePlayerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSimplePlayerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSimplePlayerDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_FilterGraph = NULL;
	m_SliderTimer = 0;
}

void CSimplePlayerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSimplePlayerDlg)
	DDX_Control(pDX, IDC_TEXT, m_text);
	DDX_Control(pDX, IDC_VIDEO_WINDOW, m_VideoWindow);
	DDX_Control(pDX, IDC_SLIDER_GRAPH, m_SliderGraph);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSimplePlayerDlg, CDialog)
	//{{AFX_MSG_MAP(CSimplePlayerDlg)
	ON_EN_CHANGE(IDC_VIDEO_WINDOW, OnChangeVideoWindow)
	ON_NOTIFY(NM_OUTOFMEMORY, IDC_SLIDER_GRAPH, OnOutofmemorySliderGraph)
	ON_BN_CLICKED(ID_BUTTON_OPEN, OnButtonOpen)
	ON_BN_CLICKED(ID_BUTTON_PLAY, OnButtonPlay)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSimplePlayerDlg message handlers


BOOL CSimplePlayerDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	m_VideoWindow.ModifyStyle(0, WS_CLIPCHILDREN);

	m_SliderGraph.SetRange(0, 1000);
	m_SliderGraph.SetPos(0);
	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}




void CSimplePlayerDlg::OnChangeVideoWindow() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CSimplePlayerDlg::OnOutofmemorySliderGraph(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	

}

void CSimplePlayerDlg::OnButtonOpen() 
{
	// TODO: Add your control notification handler code here
	CString strFilter =  
	"MPEG File (*.mpg;*.mpeg)|*.mpg;*.mpeg|"
	"AVI File (*.avi)|*.avi|"
	"Mp3 File (*.mp3)|*.mp3|"
	"Wave File (*.wav)|*.wav|"
	"All Files (*.*)|*.*|";
	CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_HIDEREADONLY, 
		strFilter, this);
	if (IDOK == dlgOpen.DoModal()) 
	{
		CString strSourceFile = dlgOpen.GetPathName();
		CString strFileName = dlgOpen.GetFileName();
		// Rebuild the file playback filter graph
		CSimplePlayerDlg::CreateGraph(strSourceFile);
		//GetDlgItem(ID_BUTTON_OPEN)->EnableWindow(FALSE);
		GetDlgItem(ID_BUTTON_PLAY)->EnableWindow(TRUE);
        m_text.SetWindowText(strFileName);
	}
	m_FilterGraph->Run();
}







// this is our must fixed ,be careful

void CSimplePlayerDlg::CreateGraph(CString strSourceFile)
{
	memcpy(PathName,strSourceFile.GetBuffer(127),127);
	PathName[128] = '\0';
//	MessageBox(PathName);

	CSimplePlayerDlg::DestroyGraph();
	m_FilterGraph = new CDXGraph();
	if (m_FilterGraph->Create())
	{
		// Render the source clip
		m_FilterGraph->RenderFile(PathName);
		// Set video window and notification window
		m_FilterGraph->SetDisplayWindow(m_VideoWindow.GetSafeHwnd());
		m_FilterGraph->SetNotifyWindow(this->GetSafeHwnd());
		// Show the first frame
    	m_FilterGraph->Pause();
	}
}
		

void CSimplePlayerDlg::OnButtonPlay() 
{
	// TODO: Add your control notification handler code here
	if (m_FilterGraph)
	{
		GetDlgItem(ID_BUTTON_PLAY)->EnableWindow(true);
		//GetDlgItem(ID_BUTTON_IMAGE)->EnableWindow(TRUE);
		GetDlgItem(ID_BUTTON_OPEN)->EnableWindow(true);
		m_FilterGraph->Run();
		// Start a timer
		if (m_SliderTimer == 0)
		{
			m_SliderTimer = SetTimer(SLIDER_TIMER, 100, NULL);
		}
	}	
}


void CSimplePlayerDlg::DestroyGraph(void)
{
	if(m_FilterGraph)
	{
		// Stop the filter graph first
		m_FilterGraph->Stop();
		m_FilterGraph->SetNotifyWindow(NULL);
		
		delete m_FilterGraph;
		m_FilterGraph = NULL;
	}
}

void CSimplePlayerDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (nIDEvent == m_SliderTimer && m_FilterGraph)
	{
		double pos = 0, duration = 1.;
		m_FilterGraph->GetCurrentPosition(&pos);
		m_FilterGraph->GetDuration(&duration);
		// Get the new position, and update the slider
		int newPos = int(pos * 1000 / duration);
		if (m_SliderGraph.GetPos() != newPos)
		{
			m_SliderGraph.SetPos(newPos);
		}
	}
/*	else if(nIDEvent == m_SaveImageTimer && m_FilterGraph)
	{
		CVideoDlg::SaveImage(m_strFilePath);
	}*/
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -