I know there are a dozen questions like this and I looked at the more popular ones, but I have had no luck in figuring out anything.
I want to make a C# *.exe that would play a sound when opened, I decided it would be OK to start with a Console Application project, but I have no idea if that is the best choice.
I have added the "file.mp3" file to the resource designer under "Other" files and set its build action to "Embedded Resource".
From there I saw the suggestion about WMPLib, which I cannot access in my project - it is not present neither in my Reference Manager, neither does "using WMPLib;" work (it raises a "could not be found" error) or the one about the "System.Media.SoundPlayer.Play();" method but I am having trouble implementing it, because my complier either says an object reference is required for it or it has no overload, because it only takes 1 arguments if I make it like "System.Media.SoundPlayer.Play("file.mp3");"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.Mum();
}
void Mum()
{
System.Media.SoundPlayer.Play();
}
}
}
SoundPlayer
...Play()
isn't a static method... Look at the MDSN docs – Broots WaymbSoundPlayer
is not able to play mp3's. "The SoundPlayer class cannot play other file types, such as .wma or .mp3. If you want to play other file types, you can use the Windows Media Player control." – Broots Waymb