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

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值