Forum > Beginners

Use music (wav) from resource

<< < (2/2)

For me the sound starts to play instantly. I am rather sure that the reason for your delay is somewhere else. Please check out the attached demo which simply executes Remy's code from the other thread. Button1 reads the stream from the resource and plays the sound. Button2 assumes that the stream already has been read when the application starts - this should be a tiny bit faster, but I am sure that this cannot be noticed.

hmmm... it seems i am a beginner.. :( but ....
There remains a delay. Even with your program. It is short but too long. I want a click with the response time of a typewriter click feedback. That must be somewhere below 100msec, or it gets inconvenient. Your example has a longer delay. Almost the same as i experienced with Remy's code which i (for demo purposes) also programmed on a form with just one button.
I am using Lazarus 2.2.0 on Win10Pro 64bit.
- So. If you have a shorter delay then that, there is something wrong at my side. Any suggestions? Is there a short silence at the beginning of your sound?
- Then the real beginner question: How to create a res file with multiple files in it. All I find is ways to put a single file in a single .res. Is there a way to put all needed sounds in one res file.
- Are there advantages/disadvantages to use *.lrs?
- Why not add the resources in the Project Options?

I tried again, and I added a 440-Hz wav file written by myself since I know then that there is not a short silent passage at the beginning of the file. Well, maybe a short delay - but the OnClick handler becomes active only when the mouse button is released. So, if you want to ignore the time the mouse button is down call the PlaySound in the OnMouseDown event rather than in OnClick.

The attached batch file adds the file wav440.wav to the sounds.res file of the test application in my previous post. There is absolutely no silence at the beginning of the file. You must compile the lazres tool which you find in the tools folder of your Lazarus application, and copy it to some directory in your path (or to the project directory). Also, rename the resource in the application: replace the "ALARM02.wav" by "WAV440.wav".

lazres is my method of choice to create resource files. Just add all files needed, or you can also put the file names, line by line, into a text file which you specify with a preceding @, e.g:

--- Code: ---dir /b *.wav > filelist.txt
lazres sounds.res @filelist.txt
del filelist.txt
--- End code ---
This way you can simply edit the contents of the res file - simply by recreating it after having edited the batch script.

I never used .rc files (which used to require the windres resource compiler - this has changed now), and I almost never add the resouces in the Project Options. The main reason is that the individual files to be added to the resource file must be available at the time when the application is built - but that's a matter of taste...

- i now know how to make a res file with multiple soundsfiles
- The delay seemed to have something to do with my soundcard settings... Everything is working fine now



[0] Message Index

[*] Previous page

Go to full version