[RESOLVED] how to add a .wav file into your project
Hey everyone. I am back :D Well anywho, I was wondering how would I go about adding a .wav file to my project? I would be doing a console application and want the .wav to be played once the program is executed. How would I go about doing this? Thanks ahead of time!
Re: how to add a .wav file into your project
Use a SoundPlayer object. I'm assuming that you're using C# 2.0. Maybe you could specify in future.
Re: how to add a .wav file into your project
Re: how to add a .wav file into your project
No need to resort to API functions, assuming that this is for .NET 2.0. I didn't mention how to get the wave file into your project in the first place though. Go to the Resources tab of the project properties and add a new audio resource. I created a console app and added the notify.wav file from my C:\Windows\Media folder to the project resources. I then ran this code:
Code:
class Program
{
static void Main(string[] args)
{
using (System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.notify))
{
sp.PlayLooping();
Console.ReadLine();
}
}
}
The app ran and played the sound until I hit Enter.
Re: how to add a .wav file into your project
Nice one JM. I never thought that the 2.0 have that kind of capabilities.
I will try that one to create a wannabe winamp application. :D
Re: how to add a .wav file into your project
Thanks! The code works for me! I was wondering is it possible to set the volume to be higher and if the volume is muted, unmute it in code?
Re: how to add a .wav file into your project
Quote:
Originally Posted by Visionary
Thanks! The code works for me! I was wondering is it possible to set the volume to be higher and if the volume is muted, unmute it in code?
I think that that would require you to use the Windows API. I couldn't tell you which functions but I know I've seen that information on the Web before. If you can't find the information on this site then a Web search should turn up what you need.
Re: how to add a .wav file into your project
Quote:
Originally Posted by mar_zim
Nice one JM. I never thought that the 2.0 have that kind of capabilities.
I will try that one to create a wannabe winamp application. :D
Note that the SoundPlayer is for wave files only. If you want to create low-level code for a media player then Windows MCI would be the way to go.
Re: how to add a .wav file into your project
Oh so it's only for wav files. Too bad I wish it could play an mp3 file. ok I'll look it up about Windows MCI.
btw thanks.
Re: how to add a .wav file into your project
Quote:
Originally Posted by mar_zim
Oh so it's only for wav files. Too bad I wish it could play an mp3 file. ok I'll look it up about Windows MCI.
btw thanks.
Getting a bit off the original topic but you may like to follow the Mentalis link in my signature and check out their Multimedia class. I'm fairly certain that it uses MCI to handle multiple sound file formats.
Re: how to add a .wav file into your project
Quote:
Originally Posted by mar_zim
Oh so it's only for wav files. Too bad I wish it could play an mp3 file. ok I'll look it up about Windows MCI.
btw thanks.
you could always convert .mp3 to .wav but it might lower the quality.