❔ Implementing sound file into program

Hello, am coding a tool. Modding tool so to say and my issue is that I can't get the sound file for a "click" implemented correctly. I checked the name now so often but its just right, the file itself is working as well and the hook is there as well must makes issues.
// Convert the resource to a byte array
byte[] soundBytes = Properties.Resources.MouseClick.wav;
// Convert the resource to a byte array
byte[] soundBytes = Properties.Resources.MouseClick.wav;
Severity Code Description Project File Line Suppression State
Error CS0117 'Resources' does not contain a definition for 'MouseClick' Merging Tool C:\Users\fall3\source\repos\Merging Tool\Merging Tool\Form1.cs 19
Severity Code Description Project File Line Suppression State
Error CS0117 'Resources' does not contain a definition for 'MouseClick' Merging Tool C:\Users\fall3\source\repos\Merging Tool\Merging Tool\Form1.cs 19
I can provide as well more code, if necessary.
7 Replies
𝕬𝖓𝖌𝖊𝖑
it appears that the resource named "MouseClick.wav" does not exist in the application's resources folder... But its definitly there... I am looking throught it.
// Define the resource name with type information (e.g., "MouseClick_Sound.wav")
string resourceName = "MouseClick_Sound.wav";

// Access the resource by name
byte[] soundBytes = (byte[])Properties.Resources.ResourceManager.GetObject(resourceName);

if (soundBytes != null)
{
// Create a MemoryStream from the byte array
using (MemoryStream memoryStream = new MemoryStream(soundBytes))
{
// Initialize the SoundPlayer with the MemoryStream
clickSoundPlayer = new SoundPlayer(memoryStream);
}
}
// Define the resource name with type information (e.g., "MouseClick_Sound.wav")
string resourceName = "MouseClick_Sound.wav";

// Access the resource by name
byte[] soundBytes = (byte[])Properties.Resources.ResourceManager.GetObject(resourceName);

if (soundBytes != null)
{
// Create a MemoryStream from the byte array
using (MemoryStream memoryStream = new MemoryStream(soundBytes))
{
// Initialize the SoundPlayer with the MemoryStream
clickSoundPlayer = new SoundPlayer(memoryStream);
}
}
Now this works now. BUT once i load up my tool, i already get conformation "sound file is not there or null" once i press the button, again. SO there's something messed up. Still am not able to get it working. Its really tough. Maybe something simple again.. who knows.. always the same.
Angius
Angius15mo ago
The file is MouseClick.wav and the resource name you're trying to use is MouseClick_Sound.wav Maybe that's why? I never used Winforms though
𝕬𝖓𝖌𝖊𝖑
Nah i actually figured that out, haha. Its like am trying switching alot of techniques, but none of'em are really working. didn't knew this could be such s time sink ^^
Anchy
Anchy15mo ago
that folder called resources is different from the project resources afaik (also dont use winforms) right click your project and click properties and select the resources tab
𝕬𝖓𝖌𝖊𝖑
well instead of using Winforms what alternatives do i have? WPF could be also the key, BUT its another whole topic ^^
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server