设为首页 加入收藏

TOP

VC++中实现连续播放多媒体(四)
2013-09-26 18:59:13 来源: 作者: 【 】 浏览:232
Tags:实现 连续 播放 多媒体

 

  (7)设置播放位置的函数:

  void CActiveMovie3::SetCurrentPosition(double newValue)

  {

  static BYTE parms[] = VTS_R8;

  InvokeHelper(0xd, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);

  }

  (8)获得音量的函数:

  long CActiveMovie3::GetVolume()

  {

  long result;

  InvokeHelper(0x13, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);

  return result;

  }

  (9)设置音量的函数:

  void CActiveMovie3::SetVolume(long nNewValue)

  {

  static BYTE parms[] = VTS_I4;

  InvokeHelper(0x13, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, nNewValue);

  }

  (10)设置自动开始播放的函数:

  void CActiveMovie3::SetAutoStart(BOOL bNewValue)

  {

  static BYTE parms[] = VTS_BOOL;

  InvokeHelper(0x28, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, bNewValue);

  }

  在Visual C++(www.cppentry.com)6.0中,一般情况都是在基于对话框的应用程序中使用ActiveMovie控件,可在菜单中依次选择"project- > Add To Project- > Components And Controls",在出现的"Components And Controls Gallery"对话框中打开"Registered Active Controls"文件夹,选中"ActiveMovie Control Object"选项,按"Insert"按钮后关闭该对话框,ActiveMovie控件便出现在程序编辑器的控件面板中,调整好控件在对话框中的位置。利用ClassWizard为ActiveMovie控件声明一个变量,设该变量的名字为m_ActiveMovie,当用户选择过待播放的文件后,为了能够播放多个文件,可以使用如下代码来向列表控件添加待播放的文件名:

  CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter);

  if(dlg.DoModal()==IDOK)

  {

  CString m_filename=dlg.GetPathName();

  m_list.AddString(m_filename);

  UpdateData(FALSE);

  }

  为了实现多媒体文件的循环播放,我们利用定时器来工作,在定时器中添加代码如下:

  CString m_filename; //定义文件变量

  double CurPos=m_ActiveMovie.GetCurrentPosition(); //获得播放位置

  if(CurPos= = 0)

  {

  //选择列表框的第一个文件

  m_list.SetCurSel(0);

  m_list.GetText(0,m_filename);

  //设置自动播放

  m_ActiveMovie.SetAutoStart(1);

  //设置文件

  m_ActiveMovie.SetFileName(m_filename);

  //播放

  m_ActiveMovie.Run();

  m_list.GetCurSel();

  //插入列表框最后

  m_list.InsertString(-1,m_filename);

  //删除用过的文件

  m_list.DeleteString(0);

  }

  CDialog::OnTimer(nIDEvent);

  }

  当需要关闭音/视频的播放时,可以用函数m_ActiveMovie.Stop()来实现。

  二、编程(www.cppentry.com)步骤

  1、 启动Visual C++(www.cppentry.com)6.0,生成一个基于对话框的程序,将该程序命名为"Player",去掉程序中对话框上的"确定" 和"取消"按钮,并加入ActiveMovie控件;

  2、 使用资源编辑器对话框添加三个按钮("选择曲目Open"、"循环播放Play"、"关闭Stop")和一个列表框;

  3、 使用ClassWizard为三个按钮和列表框添加成员变量,分别为:CButton m_stop、 CButton m_play、CListBox m_list;并且为三个按钮添加鼠标单击消息响应函数;

  4、 添加代码,编译运行程序。

  三、程序代码

  //////////////////////////////////////////////////////////////////////////////////// playerDlg.h : header file

  //{{AFX_INCLUDES()

  #include "activemovie3.h"

  //}}AFX_INCLUDES

  #if !defined(AFX_PLAYERDLG_H__F5B21A8A_5EE9_11D7_BCB5_CEB29E77AC3D__INCLUDED_)

  #define AFX_PLAYERDLG_H__F5B21A8A_5EE9_11D7_BCB5_CEB29E77AC3D__INCLUDED_

  #if _MSC_VER > 1000

  #pragma once

  #endif // _MSC_VER > 1000

  class CPlayerDlgAutoProxy;

  class CPlayerDlg : public CDialog

  {

  DECLARE_DYNAMIC(CPlayerDlg);

  friend class CPlayerDlgAutoProxy;

  // Construction

  public:

  CPlayerDlg(CWnd* pParent = NULL); // standard constructor

  virtual ~CPlayerDlg();

  // Dialog Data

  //{{AFX_DATA(CPlayerDlg)

  enum { IDD = IDD_PLAYER_DIALOG };

  CButton m_stop;

  CButton m_play;

  CListBox m_list;

  CButton m_openfile;

  CActiveMovie3 m_activemovie;

  //}}AFX_DATA

  // ClassWizard generated virtual function overrides

  //{{AFX_VIRTUAL(CPlayerDlg)

  protected:

  virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

  //}}AFX_VIRTUAL

  // Implementation

  protected:

  CPlayerDlgAutoProxy* m_pAutoProxy;

  HICON m_hIcon;

  BOOL CanExit();

  // Generated message map functions

  //{{AFX_MSG(CPlayerDlg)

  virtual BOOL OnInitDialog();

  afx_msg void OnSysCommand(UINT nID, LPARAM lParam);

  afx_msg void OnPaint();

  afx_msg HCURSOR OnQueryDragIcon();

  afx_msg void OnClose();

  virtual void OnOK();

  virtual void OnCancel();

  afx_msg void OnButton1();

  afx_msg void OnTimer(UINT nIDEvent);

  afx_msg void OnButton2();

  afx_msg void OnButton3();

  //}}AFX_MSG

  DECLARE_MESSAGE_MAP()

  };

  #endif

  //////////////////////////////////////////////////////////////// playerDlg.cpp : implementation file

  #include "stdafx.h"

  #include "player.h"

  #include "playerDlg.h"

  #include "DlgProxy.h"

  #ifdef _DEBUG

  #define new DEBUG_NEW

  #undef THIS_FILE

  static char THIS_FILE[] = __FILE__;

  #endif

  ///////////////////////////////////////////////////////////// CAboutDlg dialog used for App About

          

首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/8/8
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言代码行数统计bash实现 下一篇在VC++中定制CFileDialog

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: