没有测试,随手写的!
procedure TForm1.PlaySndFromMemoryClick(Sender: TObject);
var
f: file;
p: pointer;
fs: integer;
begin
AssignFile(f, 'hello.wav');
Reset(f,1);
fs := FileSize(f);
GetMem(p, fs);
BlockRead(f, p^, fs);
CloseFile(f);
MediaPlayer1.FileName := p
1
MediaPlayer1.Open;
2
FreeMem(p, fs);
end;
1、2两句可以用sndPlaySound(p, SND_MEMORY or SND_SYNC);代替。
当文件大于可用内存时,sndPlaySound函数就不能进行播放,要用mciSendCommand。