I know there are a lot of threads with this same topic, but for a reason I don’t understand yet, this is not working for me.
I have this project tree:

I embedded the alarm.wav to the .resx file from the Project->Properties->Resources menu.
I tried different combinations of code but nothing works.
At the moment this is the code I’m trying.
using System;
using System.Media;
using System.Windows.Forms;
using System.Threading;
using System.Globalization;
using System.ComponentModel;
using System.Resources;
using AlarmForm;
namespace Alarm
{
public partial class Form1 : Form
{
private bool estado = false;
private SoundPlayer sonido;
public Form1()
{
InitializeComponent();
ResourceManager resources = new ResourceManager(typeof(Form1));
sonido = new SoundPlayer(resources.GetStream("alarma"));
}
}
}
No error is displayed during the compilation or the runtime, but instead of the sound an error beep is heard.
Edited: Error I found trying to use Alarm.Properties
Why are you trying to use
resources.GetStream()while you can link the file directly usingAlarm.Properties? I believe that it’d be much easier. I see that you’ve also forgot to play the Sound file linked tosonidowhich represents a newSoundPlayer. Here’s a simple example that shows how to useSoundPlayerExample
Notice that: You may stop the
SoundPlayerfrom playing anytime by doingsonido.Stop()sincesonidowhich represents a new class of nameSoundPlayerwas defined underpublic partial class Form1: FormUNLESS if the void that is trying to callsonidois static.Thanks,
I hope you find this helpful 🙂