Scalabium Software |
|
Knowledge for your independence'. | |
Home Delphi and C++Builder tips |
#91: 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;
|
Copyright© 1998-2024, Scalabium
Software. All rights reserved. |