盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

不用MediaPlayer播放Midi

时间:2025/1/7作者:未知来源:盾怪网教程人气:

[摘要]你厌倦MediaPlayer吗?用了它你的EXE会大7K。 uses Windows, Classes, Forms, MMSystem, WinProcs; var wDeviceID: ...
你厌倦MediaPlayer吗?用了它你的EXE会大7K。
uses
  Windows, Classes, Forms, MMSystem, WinProcs;

var
  wDeviceID: Word;
  PlayWindow: HWnd;

procedure OpenMCI(PWindow: HWnd; FileName, DeviceType: PChar);
var
  OpenParms: Tmci_Open_Parms;
  Style: LongInt;
begin
  PlayWindow := PWindow;
  OpenParms.lpstrDeviceType := DeviceType;
  OpenParms.lpstrElementName := FileName;
  Style := Mci_Open_Type or Mci_Open_Element;
  mciSendCommand(0, MCI_OPEN, Style, LongInt(@OpenParms));
  wDeviceID := OpenParms.wDeviceID;
end;

procedure PlayMCI;
var
  Info: TMci_Play_Parms;
begin
  Info.dwCallback := PlayWindow;
  mciSendCommand(wDeviceID, MCI_PLAY, Mci_Notify, LongInt(@Info));
end;

procedure MidiPlay(MidiName: PChar);
const
  DevType: PChar='Sequencer';
begin
  if MidiName = 'StopMidi' then
    CloseMCI
  else
  begin
    OpenMci(Application.Handle, MidiName, DevType);
    PlayMci;
  end;
end;

procedure CloseMCI;
begin
  mciSendCommand(wDeviceID, MCI_CLOSE, 0, 0);
  wDeviceID := 0;
end;

end.

使用方法:
MidiPlay("Feeling.mid")); // 注意,这里必须是 PChar 或 char*
MidiPlay("StopMidi"); 

关键词:不用MediaPlayer播放Midi




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版