现在的位置: 首页 > 综合 > 正文

How can I play a wav-file from memory or BLOB-field?

2013年09月18日 ⁄ 综合 ⁄ 共 717字 ⁄ 字号 评论关闭

How can I play a wav-file from memory or BLOB-field?
Sometimes you needs to play a some sounds from own app but store these sounds in BLOB-field of table or in some external files.

To play a wav-file you must call the PlaySound procedure which have the few parameters - sound (which you want to play), handle of file with resource (only for wav from exe/dll-file) and flags for playing.

For example, if you want to play a wav from BLOB, you can use the next code:

var
  b: TBlobStream;
  m: TMemoryStream;
begin
  b := TBlobStream.Create(yourTable, bmRead);
  try
    m := TMemoryStream.Create;
    try
      {copy a wav from BLOB into memory}
      m.CopyFrom(b, b.Size);

      {Play it but if we'll have an error, raise exception}
      Win32Check(PlaySound(m.Memory, 0, SND_SYNC or SND_MEMORY));
    finally
      m.Free
    end;
  finally
    b.Free
  end;
end;

抱歉!评论已关闭.