Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C#, SoundPlayer, and Console application

Status
Not open for further replies.

banswara

Programmer
Sep 27, 2002
16
CA
I am trying to get a C# console program to play WAV files. The following code works in a Windows Application:

FileStream fs = new FileStream(@"c:\oou.wav",FileMode.Open, FileAccess.Read);
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(fs);
sp.Play();


When I port the same code into a Console Application, there is only a very brief output from the sound card the first time I invoke the code, subsequent invocations pass so quickly that there is no apparent audio whatsoever (the WAV file I am testing with is about 8 secs. long).

What do I need to do to make this work?
 
Try with this...
You run the application without debugging (instead of F5 press CTRL+F5).
If you don't want to run the application without the debugger, at the end of the application code add:
Console.ReadLine()

Sharing the best from my side...

--Prashant--
 
I changed the sp.play() to sp.playsync() and the code works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top