MCI_PLAY_PARMS dwCallback 如何获取回调事件
时间:2011-12-09
来源:互联网
我的问题就是使用mciSendCommand如何获取当前播放音乐时间点,精度是毫秒。
回调事件如何捕捉,请高手指点,困惑了很久了。谢谢!
代码如下
unit mciPas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,mmsystem, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
mciOpenParms: MCI_OPEN_PARMS;
m_MCIDeviceID: MCIDEVICEID;
mciPlayParms:MCI_PLAY_PARMS;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//初始化参数
procedure TForm1.Button1Click(Sender: TObject);
VAR
file_name_: String;
begin
file_name_ := 'D:\test.wma';
mciOpenParms.lpstrDeviceType:='''';
mciOpenParms.lpstrElementName := PChar(file_name_);
mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT,DWORD(@mciOpenParms));
m_MCIDeviceID := mciOpenParms.wDeviceID;
mciPlayParms.dwCallback := Handle;
mciPlayParms.dwFrom := 29*1000;
mciPlayParms.dwTo := mciPlayParms.dwFrom+1500;
end;
//开始播放
procedure TForm1.Button2Click(Sender: TObject);
begin
mciSendCommand(m_MCIDeviceID,MCI_PLAY,MCI_FROM or MCI_TO or MCI_NOTIFY,integer(@mciPlayParms));
end;
//如何获取到当前播放时间点
/*
windows sdk 说明
The MCI_PLAY_PARMS structure contains positioning information for the MCI_PLAY command.
typedef struct {
DWORD dwCallback;
DWORD dwFrom;
DWORD dwTo;
} MCI_PLAY_PARMS;
Members
dwCallback
The low-order word specifies a window handle used for the MCI_NOTIFY flag.
dwFrom
Position to play from.
dwTo
Position to play to.
Remarks
When assigning data to the members of this structure, set the corresponding flags in the fdwCommand parameter of the mciSendCommand function to validate the members.
*/
end.
回调事件如何捕捉,请高手指点,困惑了很久了。谢谢!
代码如下
unit mciPas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,mmsystem, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
mciOpenParms: MCI_OPEN_PARMS;
m_MCIDeviceID: MCIDEVICEID;
mciPlayParms:MCI_PLAY_PARMS;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//初始化参数
procedure TForm1.Button1Click(Sender: TObject);
VAR
file_name_: String;
begin
file_name_ := 'D:\test.wma';
mciOpenParms.lpstrDeviceType:='''';
mciOpenParms.lpstrElementName := PChar(file_name_);
mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT,DWORD(@mciOpenParms));
m_MCIDeviceID := mciOpenParms.wDeviceID;
mciPlayParms.dwCallback := Handle;
mciPlayParms.dwFrom := 29*1000;
mciPlayParms.dwTo := mciPlayParms.dwFrom+1500;
end;
//开始播放
procedure TForm1.Button2Click(Sender: TObject);
begin
mciSendCommand(m_MCIDeviceID,MCI_PLAY,MCI_FROM or MCI_TO or MCI_NOTIFY,integer(@mciPlayParms));
end;
//如何获取到当前播放时间点
/*
windows sdk 说明
The MCI_PLAY_PARMS structure contains positioning information for the MCI_PLAY command.
typedef struct {
DWORD dwCallback;
DWORD dwFrom;
DWORD dwTo;
} MCI_PLAY_PARMS;
Members
dwCallback
The low-order word specifies a window handle used for the MCI_NOTIFY flag.
dwFrom
Position to play from.
dwTo
Position to play to.
Remarks
When assigning data to the members of this structure, set the corresponding flags in the fdwCommand parameter of the mciSendCommand function to validate the members.
*/
end.
作者: yhcustc 发布时间: 2011-12-09
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, mmsystem,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
function GetPosition():DWORD;
procedure MCINotify(Var Msg:TMessage);Message MM_MCINOTIFY;
public
{ Public declarations }
mciOpenParms: MCI_OPEN_PARMS;
m_MCIDeviceID: MCIDEVICEID;
mciPlayParms:MCI_PLAY_PARMS;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetPosition():DWORD; // 获取播放位置(毫秒)
var
mci_Pos : MCI_STATUS_PARMS;
ret: integer;
pszText: PChar; uLength: UINT;
begin
Result := 0;
mci_Pos.dwCallback := Handle;
mci_Pos.dwItem := MCI_STATUS_POSITION;
ret:=mciSendCommand(
m_MCIDeviceID,
MCI_STATUS,
MCI_WAIT or MCI_STATUS_ITEM,
DWORD(@mci_Pos));
if 0<>ret then
begin
uLength := 255;
GetMem( pszText, uLength );
mciGetErrorString(ret, pszText, uLength);
self.Caption := pszText;
FreeAndNil( pszText );
end;
Result := mci_Pos.dwReturn;
end;
procedure TForm1.MCINotify(Var Msg:TMessage);
begin
case (Msg.wParam) of
MCI_NOTIFY_FAILURE:
showmessage('出现错误,播放停止!');
MCI_NOTIFY_ABORTED: showmessage('ABORTED!');
MCI_NOTIFY_SUPERSEDED:showmessage('SUPERSEDED!');
MCI_NOTIFY_SUCCESSFUL://showmessage();
begin
self.Caption := '播放结束!';
end;
else
showmessage('UNKOWN!');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
VAR
file_name_: String;
begin
file_name_ := 'D:\test.wma';
mciOpenParms.lpstrDeviceType:='';
mciOpenParms.lpstrElementName := PChar(file_name_);
mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT,DWORD(@mciOpenParms));
m_MCIDeviceID := mciOpenParms.wDeviceID;
mciPlayParms.dwCallback := Handle;
mciPlayParms.dwFrom := 1;
mciPlayParms.dwTo := mciPlayParms.dwFrom+2000*10;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
mciSendCommand(m_MCIDeviceID,MCI_PLAY,MCI_FROM or MCI_TO or MCI_NOTIFY,integer(@mciPlayParms));
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
self.Caption := inttostr(GetPosition());
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, mmsystem,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
function GetPosition():DWORD;
procedure MCINotify(Var Msg:TMessage);Message MM_MCINOTIFY;
public
{ Public declarations }
mciOpenParms: MCI_OPEN_PARMS;
m_MCIDeviceID: MCIDEVICEID;
mciPlayParms:MCI_PLAY_PARMS;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetPosition():DWORD; // 获取播放位置(毫秒)
var
mci_Pos : MCI_STATUS_PARMS;
ret: integer;
pszText: PChar; uLength: UINT;
begin
Result := 0;
mci_Pos.dwCallback := Handle;
mci_Pos.dwItem := MCI_STATUS_POSITION;
ret:=mciSendCommand(
m_MCIDeviceID,
MCI_STATUS,
MCI_WAIT or MCI_STATUS_ITEM,
DWORD(@mci_Pos));
if 0<>ret then
begin
uLength := 255;
GetMem( pszText, uLength );
mciGetErrorString(ret, pszText, uLength);
self.Caption := pszText;
FreeAndNil( pszText );
end;
Result := mci_Pos.dwReturn;
end;
procedure TForm1.MCINotify(Var Msg:TMessage);
begin
case (Msg.wParam) of
MCI_NOTIFY_FAILURE:
showmessage('出现错误,播放停止!');
MCI_NOTIFY_ABORTED: showmessage('ABORTED!');
MCI_NOTIFY_SUPERSEDED:showmessage('SUPERSEDED!');
MCI_NOTIFY_SUCCESSFUL://showmessage();
begin
self.Caption := '播放结束!';
end;
else
showmessage('UNKOWN!');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
VAR
file_name_: String;
begin
file_name_ := 'D:\test.wma';
mciOpenParms.lpstrDeviceType:='';
mciOpenParms.lpstrElementName := PChar(file_name_);
mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT,DWORD(@mciOpenParms));
m_MCIDeviceID := mciOpenParms.wDeviceID;
mciPlayParms.dwCallback := Handle;
mciPlayParms.dwFrom := 1;
mciPlayParms.dwTo := mciPlayParms.dwFrom+2000*10;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
mciSendCommand(m_MCIDeviceID,MCI_PLAY,MCI_FROM or MCI_TO or MCI_NOTIFY,integer(@mciPlayParms));
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
self.Caption := inttostr(GetPosition());
end;
end.
作者: extcsdn 发布时间: 2011-12-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28