|
-
Nov 7th, 2006, 11:14 PM
#1
Thread Starter
Member
[RESOLVED] how to add a .wav file into your project
Hey everyone. I am back 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!
Last edited by Visionary; Nov 9th, 2006 at 10:37 AM.
-
Nov 7th, 2006, 11:26 PM
#2
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.
-
Nov 8th, 2006, 05:08 AM
#3
Re: how to add a .wav file into your project
-
Nov 8th, 2006, 05:18 AM
#4
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.
-
Nov 8th, 2006, 06:28 PM
#5
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.
-
Nov 8th, 2006, 08:59 PM
#6
Thread Starter
Member
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?
-
Nov 8th, 2006, 09:04 PM
#7
Re: how to add a .wav file into your project
 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.
-
Nov 8th, 2006, 09:06 PM
#8
Re: how to add a .wav file into your project
 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. 
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.
-
Nov 8th, 2006, 09:39 PM
#9
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.
-
Nov 8th, 2006, 09:42 PM
#10
Re: how to add a .wav file into your project
 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.
-
Nov 8th, 2006, 10:25 PM
#11
Thread Starter
Member
Re: how to add a .wav file into your project
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|