一个简单的基于 DirectShow 的播放器 2(对话框类)
上篇文章分析了一个封装DirectShow各种接口的封装类(CDXGraph):一个简单的基于 DirectShow 的播放器 1(封装类)
本文继续上篇文章,分析一下调用这个封装类(CDXGraph)的对话框类(CSimplePlayerDlg),看看在MFC中如何使用这个类(CDXGraph)。
首先来看看CSimplePlayerDlg这个类的定义,瞧瞧SimplePlayerDlg.h这个头文件。
/* 雷霄骅 * 中国传媒大学/数字电视技术 * leixiaohua1020@126.com * */ // SimplePlayerDlg.h : header file // #if !defined(AFX_SIMPLEPLAYERDLG_H__3599FE35_3322_4CC7_B30B_6D6050C2EDFF__INCLUDED_) #define AFX_SIMPLEPLAYERDLG_H__3599FE35_3322_4CC7_B30B_6D6050C2EDFF__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 ///////////////////////////////////////////////////////////////////////////// // CSimplePlayerDlg dialog #include <streams.h> #include "CDXGraph.h" #define SLIDER_TIMER 100 class CSimplePlayerDlg : public CDialog { // Construction public: CSimplePlayerDlg(CWnd* pParent = NULL); // standard constructor ~CSimplePlayerDlg(); // Dialog Data //{{AFX_DATA(CSimplePlayerDlg) enum { IDD = IDD_SIMPLEPLAYER_DIALOG }; CSliderCtrl mSliderGraph; CStatic mVideoWindow; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSimplePlayerDlg) public: virtual BOOL PreTranslateMessage(MSG* pMsg); virtual BOOL DestroyWindow(); protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; CDXGraph * mFilterGraph; // Filter Graph封装 CString mSourceFile; // 源文件 UINT mSliderTimer; // 定时器ID //创建Graph void CreateGraph(void); // 创建Filter Graph void DestroyGraph(void); // 析构Filter Graph void RestoreFromFullScreen(void); // Just for testing... HRESULT FindFilterByInterface(REFIID riid, IBaseFilter** ppFilter); void ShowVRPropertyPage(void); // Generated message map functions //{{AFX_MSG(CSimplePlayerDlg) virtual BOOL OnInitDialog(); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); //打开 afx_msg void OnButtonOpen(); //播放 afx_msg void OnButtonPlay(); //暂停 afx_msg void OnButtonPause(); //停止 afx_msg void OnButtonStop(); afx_msg void OnButtonGrab(); afx_msg void OnButtonFullscreen(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnTimer(UINT nIDEvent); afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg void OnButtonTest(); //}}AFX_MSG afx_msg LRESULT OnGraphNotify(WPARAM inWParam, LPARAM inLParam); DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_SIMPLEPLAYERDLG_H__3599FE35_3322_4CC7_B30B_6D6050C2EDFF__INCLUDED_)
从头文件来看,和普通的MFC对话框类并没有什么不同,无非是一些消息响应函数,或者MFC控件对应的类。需要注意一下,有一个变量:
CDXGraph * mFilterGraph
接下来看看CSimplePlayerDlg函数的实现部分吧。
OnButtonOpen():打开媒体文件按钮的响应函数
//打开 void CSimplePlayerDlg::OnButtonOpen() { // TODO: Add your control notification handler code here CString strFilter = "AVI File (*.avi)|*.avi|"; strFilter += "MPEG File (*.mpg;*.mpeg)|*.mpg;*.mpeg|"; strFilter += "Mp3 File (*.mp3)|*.mp3|"; strFilter += "Wave File (*.wav)|*.wav|"; strFilter += "All Files (*.*)|*.*|"; CFileDialog dlgOpen(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_HIDEREADONLY, strFilter, this); if (IDOK == dlgOpen.DoModal()) { mSourceFile = dlgOpen.GetPathName(); // Rebuild the file playback filter graph //创建Graph CreateGraph(); } }
其中CreateGraph()函数如下所示:
//创建Graph void CSimplePlayerDlg::CreateGraph(void) { //(如果有)销毁Graph DestroyGraph(); //新建一个核心类 mFilterGraph = new CDXGraph(); if (mFilterGraph->Create()) { // Render the source clip mFilterGraph->RenderFile(mSourceFile); // Set video window and notification window mFilterGraph->SetDisplayWindow(mVideoWindow.GetSafeHwnd()); mFilterGraph->SetNotifyWindow(this->GetSafeHwnd()); // Show the first frame mFilterGraph->Pause(); } }
与CreateGraph()相反的还有一个DestroyGraph()
//(如果有)销毁Graph void CSimplePlayerDlg::DestroyGraph(void) { if (mFilterGraph) { // Stop the filter graph first mFilterGraph->Stop(); mFilterGraph->SetNotifyWindow(NULL); delete mFilterGraph; mFilterGraph = NULL; } }
OnButtonPlay():播放按钮的响应函数
//播放 void CSimplePlayerDlg::OnButtonPlay() { if (mFilterGraph) { mFilterGraph->Run(); // Start a timer if (mSliderTimer == 0) { mSliderTimer = SetTimer(SLIDER_TIMER, 100, NULL); } } }
OnButtonPause():暂停按钮的响应函数
void CSimplePlayerDlg::OnButtonPause() { if (mFilterGraph) { mFilterGraph->Pause(); // Start a timer if (mSliderTimer == 0) { mSliderTimer = SetTimer(SLIDER_TIMER, 100, NULL); } } }
OnButtonStop():停止按钮的响应函数
void CSimplePlayerDlg::OnButtonStop() { if (mFilterGraph) { mFilterGraph->SetCurrentPosition(0); mFilterGraph->Stop(); // Stop the timer if (mSliderTimer) { KillTimer(mSliderTimer); mSliderTimer = 0; } } }
其他的函数不再一一列举,但意思都是一样的。
播放器源代码下载:http://download.csdn.net/detail/leixiaohua1020/6453467
一个简单的基于 DirectShow 的播放器 2(对话框类)的更多相关文章
- 一个简单的基于 DirectShow 的播放器 1(封装类)
DirectShow最主要的功能就是播放视频,在这里介绍一个简单的基于DirectShow的播放器的例子,是用MFC做的,今后有机会可以基于该播放器开发更复杂的播放器软件. 注:该例子取自于<D ...
- 转:最简单的基于 DirectShow 的视频播放器
50行代码实现的一个最简单的基于 DirectShow 的视频播放器 本文介绍一个最简单的基于 DirectShow 的视频播放器.该播放器对于初学者来说是十分有用的,它包含了使用 DirectSho ...
- 50行代码实现的一个最简单的基于 DirectShow 的视频播放器
本文介绍一个最简单的基于 DirectShow 的视频播放器.该播放器对于初学者来说是十分有用的,它包含了使用 DirectShow 播放视频所有必备的函数. 直接贴上代码,具体代码的含义都写在注释中 ...
- 一个简单有趣的Python音乐播放器
(赠新手,老鸟绕行0.0) Python版本:3.5.2 源码如下: __Author__ = "Lance#" # -*- coding = utf-8 -*- #导入相应模块 ...
- 自己实现一个简单的网络音乐mp3播放器
大繁至简,把思路搞清楚才是最重要的,如何去做依托于使用什么来实现这项功能 列出我使用的基本类 NSURLSessionDataTask 数据获取类 NSFileHandle 数据缓存和数据读取类 Au ...
- 最简单的基于DirectShow的示例:视频播放器自定义版
===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...
- 最简单的基于DirectShow的示例:视频播放器图形界面版
===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...
- 最简单的基于DirectShow的示例:视频播放器
===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...
- 最简单的基于DirectShow的示例:获取Filter信息
===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...
随机推荐
- Java程序员必须掌握的线程知识-Callable和Future
Callable和Future出现的原因 创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口. 这2种方式都有一个缺陷就是:在执行完任务之后无法获取执行结果. 如果需 ...
- Android动态换肤(一、应用内置多套皮肤)
动态换肤在很多android应用中都有使用,用户根据自己的喜好设置皮肤主题,可以增强用户使用应用的舒适度. Android换肤可以分为很多种,它们从使用方式,用户体验以及项目框架设计上体现了明显的差异 ...
- Swift变量名的一种玩法
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 是的,Swift的变量名可以用任何合法的Unicode字符,这 ...
- linux ubuntu系统下MySQL的安装及设置
debian下安装MySQL:1.构建源或使用光盘镜像,当然你插入光盘也没问题2.有源时本地文件的源配置:修改/etc/apt/sources.list文件, 示例:deb http://192.16 ...
- ROS_Kinetic_22 使用ROS的qt插件即ros_qtc_plugin实现Hi ROS!!!!
官网已经更新了教程说明,在此特别说明: https://github.com/ros-industrial/ros_qtc_plugin/wiki This wiki explains the pro ...
- SSH深度历险(八) 剖析SSH核心原理+Spring依赖注入的三种方式
在java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依 ...
- 学习TensorFlow,浅析MNIST的python代码
在github上,tensorflow的star是22798,caffe是10006,torch是4500,theano是3661.作为小码农的我,最近一直在学习tensorflow,主要使用pyth ...
- iOS中 本地通知/本地通知详解 韩俊强的博客
布局如下:(重点讲本地通知) iOS开发者交流QQ群: 446310206 每日更新关注:http://weibo.com/hanjunqiang 新浪微博 Notification是智能手机应用编 ...
- J2EE Exception:WELD-001408 Unsatisfied dependencies for type [SelectModelFactory] with qualifiers [@
Issue: When you inject some resources using @Inject, you may encounter following exception after app ...
- Android的stateListDrawable,layerDawable,clipdrawable,AnimationDarwable介绍-android学习之旅(五十五)
StatelistDrawable资源 代码示例 <?xml version="1.0" encoding="utf-8"?> <select ...