李维的书里有讲
服务端
function TWavsService.GetWavFile(const sFileName: String): String;
var
ams : TMemoryStream;
ass : TStringStream;
begin
Result := '';
if (FileExists(sAppPath + 'wavs/' + sFileName)) then
begin
ams := TMemoryStream.Create;
ams.LoadFromFile(sAppPath + 'wavs/' + sFileName);
ass := TStringStream.Create('');
try
MimeEncodeStream(ams, ass);
Result := ass.DataString;
finally
ass.Free;
ams.Free;
end;
end;
end;
客户端
procedure TForm2.bbtnPlayWavClick(Sender: TObject);
var
aIntf : IWavsService;
ass : TStringStream;
ams : TMemoryStream;
sWav : String;
sFileName : String;
begin
aIntf := HTTPRIO1 as IWavsService;
try
sFileName := lbWavs.Items[lbWavs.ItemIndex];
sFileName := GetWavFileName(sFileName);
sWav := aIntf.GetWavFile(sFileName);
ams := TMemoryStream.Create;
ass := TStringStream.Create(sWav);
MimeDecodeStream(ass, ams);
ams.SaveToFile(sFileName);
Self.MediaPlayer1.FileName := sFileName;
Self.MediaPlayer1.Open;
Self.MediaPlayer1.Play;
finally // wrap up
ass.Free;
ams.Free;
aIntf := nil;
end
// try/finally
end;