我的问题就是使用mciSendCommand如何获取当前播放音乐时间点,精度是毫秒。
回调事件如何捕捉,请高手指点,困惑了很久了。谢谢!代码如下unit mciPas;interfaceuses
  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;
 MembersdwCallbackThe low-order word specifies a window handle used for the MCI_NOTIFY flag.dwFromPosition to play from.dwToPosition to play to. ResWhen 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.

解决方案 »

  1.   

    一个WAV文件播放所发生的事件序列为:(1)命令播放WAV文件并立即返回;(2)播放WAV文 件;(3)完成后发送通知消息MM_MCINOTIFY。所以你加入如下代码:
    private
        { Private declarations }
        procedure MCINotify(Var Msg:TMessage);Message MM_MCINOTIFY;procedure TForm1.MCINotify(Var Msg:TMessage);
    begin
      showmessage('播放完毕!');
    end;
      

  2.   

    谢谢 extcsdn,我使用的是指定区间播放,当播放自动停止时没有出发消息。
    后来采用发送命令再次发送命令查询状态才能获取当前播放的位置。
    mciDeviceID := mciOpenParms.wDeviceID;
          mciStatus.dwItem := MCI_STATUS_LENGTH;
          mciSendCommand(mciDeviceID, MCI_STATUS,MCI_STATUS_ITEM, Longint(@mciStatus));
          length_ := mciStatus.dwReturn;这样才能查询到当前播放位置精确到毫秒,我想要不停的发送命令才能获取到,当播放完成后,我也不知道,还在不停的发送,发送频率间隔比较难控制。我觉的既然有回调函数,当播放位置发送改变时,就应该调用我的回调事件中来。