Playing WAV from memory using sndPlaySound

Source: Internet
Author: User

Sometimes, we write the program need to play music, generally we will use the following ways: 1. Place music files in a specific directory, such as Sound,wav,music for the program to read and play; 2. Use resources to store music. Some people may also use this method, but most people might have to release the music files from the resources before they read the playback. The way I'm going to present today is to load the music files directly into memory and then read them from memory. All right, here's the code:
Var
Hresinfo:thandle;
Ptrsound:pointer;
Begin
Hresinfo: = FindResource (hinstance, ' sound ', ' WAV ');
HRes: = LoadResource (hinstance, hresinfo);
If hres >
Begin
Ptrsound: = Lockresource (hres);
End
sndPlaySound (Ptrsound, Snd_async or snd_memory);
End
The core code is given, as long as we have to make a resource file, first, we first create a file with the extension RC

Where sound is the resource name, the WAV resource type, and the girl.wav is the music file.
Then we put the music file and the RC file in the same directory, compiled with BRCC32, the directory will generate a res extension file, the file will be placed in the Delphi project folder, in the unit's implementation {$R *.DFM} under the {$R Girl.res}, the final compilation can be.

Http://www.lsworks.net/article/1.html

Playing WAV from memory using sndPlaySound

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.