to achang,loeh,我只给出例程中的关于MediaPlayer控制部分,程序不难,应该很容易
看懂,程序在WINDOWS9x+DELPHI6上通过,只要设置MediaPlayer的DeviceType=Autoselected
便可以同时播发MIDI和WAVE格式的文件,另外如果你想长时间的循环播放声音列表,最好
不要用MediaPlayer,它会产生很多问题,例如,系统资源的耗尽等,建议用API函数操作
感兴趣的话可以跟我联系。
function TmainForm.Initplayer: Boolean;//本过程用于初始化MediaPlayer
var ErrorString:string;
begin
Result:=False;
try
MediaPlayer1.Close;
MediaPlayer1.Open;
MediaPlayer1.Notify:=True;
result:=true;
except
ErrorString:='系统出错:'+InttoStr(Error)+#13#10;
MessageDlg(ErrorString + MediaPlayer1.ErrorMessage,mtError,[mbOK],0);
end;
end;
procedure TmainForm.MediaPlayer1Click(Sender: TObject;
Button: TMPBtnType;
vardo
Default: Boolean);
begin
inherited;
if Button=btStop then
begin
MediaPlayer1.Previous;
Gauge1.Progress:=0;
MediaPlayer1.EnabledButtons:=[btPlay];
MediaPlayer1.Notify:=false;
end
else
if Button=btPlay then
begin
///数据库操作///
{InitialData;
SaveData;
DeleteData(ComboOrder.Text);}
MediaPlayer1.FileName:=ListBox1.Items[ListBox1.ItemIndex];
if Initplayer then
begin
MediaPlayer1.EnabledButtons:=[btStop];
end;
with gauge1do
begin
Maxvalue:=Listbox1.Items.Count;
Progress:=0;
end;
end;
end;
procedure TmainForm.MediaPlayer1Notify(Sender: TObject);
begin
inherited;
if MediaPlayer1.Notify=true //或者用(MediaPlayer1.NotifyValue=nvSuccessful) and (MediaPlayer1.Mode=mpStopped)
then
begin
MediaPlayer1.Previous;
if ((Listbox1.ItemIndex+1)<(listbox1.Items.Count)) then
begin
Listbox1.ItemIndex:=Listbox1.ItemIndex+1;
Gauge1.Progress:=Gauge1.Progress+1;
end
else
begin
Listbox1.ItemIndex:=0;
Gauge1.Progress:=0
end;
MediaPlayer1.FileName:=Listbox1.Items[Listbox1.itemindex];
if Initplayer then
begin
MediaPlayer1.EnabledButtons:=[btStop];
MediaPlayer1.Play;
end;
end;
end;