Forum > Audio and Video

PlaySound doesn't play sound from resource

<< < (5/5)

wp:
The easiest way to add a resource to an application - without any other tools - is to go to "Project" > "Project options" > "Project options" > "Resources"; click "Add", switch the file type filter to "All files (*.*)"; select the file to be added > "Open". The file is now listed in the "Resources" windows. Note the name in the "Resource" column - this is the name which you must use to open the resource in the application. To the left of it, you see "RCDATA" in the "Type" column; this is the type of the resource which you usually must specifiy when you load the resource (you must preceed the type name with an "RT_").

If you follow this, your "Bell.wav" will be in the resources as BELL of type RCDATA. In order to open it in your application as a resource stream you must write

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  resStream := TResourceStream.Create(HINSTANCE, 'BELL', RT_RCDATA);
A little disadvantage of this method is that the files added to the resources must be available whenever the application is compiled. The "lazres" utility, on the other hand, allows you to create resource files independent of compilation.

shyub:
wp, thank you very much!

KodeZwerg:

--- Quote from: wp on May 25, 2024, 07:03:31 pm ---The easiest way to add a resource to an application - without any other tools - is to go to "Project" > "Project options" > "Project options" > "Resources"; click "Add", switch the file type filter to "All files (*.*)"; select the file to be added > "Open". The file is now listed in the "Resources" windows. Note the name in the "Resource" column - this is the name which you must use to open the resource in the application. To the left of it, you see "RCDATA" in the "Type" column; this is the type of the resource which you usually must specifiy when you load the resource (you must preceed the type name with an "RT_").

If you follow this, your "Bell.wav" will be in the resources as BELL of type RCDATA. In order to open it in your application as a resource stream you must write

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  resStream := TResourceStream.Create(HINSTANCE, 'BELL', RT_RCDATA);
A little disadvantage of this method is that the files added to the resources must be available whenever the application is compiled. The "lazres" utility, on the other hand, allows you to create resource files independent of compilation.

--- End quote ---
or, also within this tool called Lazarus, create a new file, add
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---LANGUAGE 0,0#define RCDATA 10Bell RCDATA "Bell.wav"save file as "sounds.rc" in project folder.
copy bell.wav into project folder.
inside code use "{$R 'sounds.rc'}" near under "implementation"
in theory its the same as adding by project options, since its just text its for me more comfortable.
requires a full fpc or lazarus installation, wherever the binary resource compiler is deployed with.

TRon:

--- Quote from: wp on May 25, 2024, 07:03:31 pm ---The "lazres" utility, on the other hand, allows you to create resource files independent of compilation.

--- End quote ---
It is advisable not to use it anymore. See KodeZwerg's reply.


--- Quote from: KodeZwerg on May 25, 2024, 07:55:56 pm ---requires a full fpc or lazarus installation, wherever the binary resource compiler is deployed with.

--- End quote ---
And in case it is unable to locate it fpc tries to fall back to winres (which can be optionally configured and installed manually). The fpcres utility has to go through 2 releases to get fully integrated (into the build process).

Navigation

[0] Message Index

[*] Previous page

Go to full version