https://zhidao.baidu.com/question/44595991
假定你的foo.rc如下bai: music1 mymp3 a01.mp3 music2 mymp3 a02.mp3 //依次为资源名、类型du、具体文件名(zhi将在资源编译后被加入到foo.res文件中),在程序里使dao用的是其资源名,而不是本名。 procedure play(filename:string); var res:TResourceStream; begin //filename:='music1'; if fileexists('temp.mp3') then deletefile('temp.mp3'); sleep(100); res:=TResourceStream.Create(hinstance,filename,'mymp3'); res.SaveToFile('temp.mp3'); res.Free; sleep(100); //res.Seek(0,soEnd); //if res.Position=res.Size then showmessage(inttostr(res.size)); MCIsendstring('open temp.mp3 type mpegvideo alias tp',nil,0,0); MCISendString('play tp from 0',nil,0,0); end; procedure TForm1.Button1Click(Sender: TObject); begin play('music1');//播放第一首 end; procedure TForm1.Timer1Timer(Sender: TObject); var ret:array[0..255]of char; begin MCISendString('status tp mode',ret,sizeof(ret),0); if string(ret)='stopped' then begin MCISendString('close tp',nil,0,0); play('music2');//播放第二首 end; end;
*************************
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, mmsystem;
type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm} {$R foo.res}
procedure play(filename:string); var res:TResourceStream; begin //filename:='music1'; if fileexists('temp.mp3') then deletefile('temp.mp3'); sleep(100); res:=TResourceStream.Create(hinstance,filename,'mymp3'); res.SaveToFile('temp.mp3'); res.Free; sleep(100); //res.Seek(0,soEnd); //if res.Position=res.Size then showmessage(inttostr(res.size)); MCIsendstring('open temp.mp3 type mpegvideo alias tp',nil,0,0); MCISendString('play tp from 0',nil,0,0); end; procedure TForm1.Button1Click(Sender: TObject); begin play('music1');//播放第一首 end;
end.
|
请发表评论