Forum > Audio and Video
PlaySound doesn't play sound from resource
karloromic:
--- 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";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LResources, MMSystem; type { TForm1 } TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin PlaySound('ONLINE2', HInstance, SND_RESOURCE);end; end.
Example project:
https://ufile.io/xw3w18ai
Remy Lebeau:
--- Quote from: karloromic on September 25, 2019, 12:36:16 pm ---
--- 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";}};} ---PlaySound('ONLINE2', HInstance, SND_RESOURCE);
--- End quote ---
In your project1.lpi file, your "ONLINE2" resource is set to a resource type of "RCDATA":
--- Code: ---<Resource_0 FileName="audio\online2.wav" Type="RCDATA" ResourceName="ONLINE2"/>
--- End code ---
It needs to be set to a resource type of "WAVE" instead, or else PlaySound() will not be able to find it at runtime.
Otherwise, you can manually obtain a memory pointer to the resource data using FindResource()/LoadResource()/LockResource(), and then use SND_MEMORY instead of SND_RESOURCE to play it.
karloromic:
Setting resource type "WAVE" instead of "RCDATA" doesnt work as it is automatically corrected on compilation..
--- Quote from: Remy Lebeau on September 25, 2019, 09:58:08 pm ---Otherwise, you can manually obtain a memory pointer to the resource data using FindResource()/LoadResource()/LockResource(), and then use SND_MEMORY instead of SND_RESOURCE to play it.
--- End quote ---
Can you give me an simple example of that? Thank you
winni:
Allways trouble with the Windows resource files. Neverending story.
Use the Lazarus resource files. You have to convert your WAV-file (or any other file) to an .lrs file:
lazres sound.lrs ONLINE2.WAV
And then copy the sound.lrs to your source file directory.
And in your unit1 you have to 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";}};} ---implementation {$I sound.lrs }
One problem less.
Winni
karloromic:
--- Quote from: winni on September 25, 2019, 10:38:51 pm ---Allways trouble with the Windows resource files. Neverending story.
Use the Lazarus resource files. You have to convert your WAV-file (or any other file) to an .lrs file:
lazres sound.lrs ONLINE2.WAV
And then copy the sound.lrs to your source file directory.
And in your unit1 you have to 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";}};} ---implementation {$I sound.lrs }
One problem less.
Winni
--- End quote ---
Wow, that solved it! Thanks!
And also syntax correction:
--- 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";}};} ---implementation {$I sound.lrs }
should be used on initialization:
--- 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";}};} ---initialization{$I sound.lrs}
Navigation
[0] Message Index
[#] Next page