Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello i'm trying to develop chat facility, in which i use one 2 textbox and one button1.
whenver the user enter the message in one textbox by clicking button, then a sound will be dispaly during the message display in another textbox(say textbox2)

so can u help me in solving the problm...
Posted

1 solution

Hi,

If your sound file is a .wav file, you can try this:
C#
protected void button1_Click(object sender, EventArgs e)
{
     byte[] result = System.IO.File.ReadAllBytes("sound.wav");
     System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
     ms.Position = 0;
     System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(ms);
     soundPlayer.PlayLooping(); // play the sound file
     // now, display the message in the other textbox
     soundPlayer.Stop(); // stop playing the sound
}

If your audio file isn't a .wav file, then have a look here:
http://www.crowsprogramming.com/archives/58[^]
You can also convert your audio file to a .wav file.
Have a look at this list of audio conversion software[^].

Hope this helps.
 
Share this answer
 
v5
Comments
Cto Manav Parasrampuria 5-Jan-13 10:38am    
not work...error message show:

The wave header is corrupt.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The wave header is corrupt.

Source Error:


Line 18:
Line 19: System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer("http://localhost:13769/ASPNETCHAT/sound.au");
Line 20: soundPlayer.PlayLooping(); // play the sound filehttp:
Line 21: // now, display the message in the other textbox
Line 22: soundPlayer.Stop(); // stop playing the sound
Thomas Daniels 5-Jan-13 10:43am    
Hi,
I updated my answer.
Cto Manav Parasrampuria 5-Jan-13 11:22am    
hello...not worked,,,,following error display

URI formats are not supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: URI formats are not supported.

Source Error:


Line 16: protected void Button1_Click(object sender, EventArgs e)
Line 17: {
Line 18: byte[] result = System.IO.File.ReadAllBytes("http://localhost:13769/ASPNETCHAT/sound.au");
Line 19: System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
Line 20: ms.Position = 0;
Thomas Daniels 5-Jan-13 11:27am    
Change
byte[] result = System.IO.File.ReadAllBytes("http://localhost:13769/ASPNETCHAT/sound.au");
into
byte[] result = System.IO.File.ReadAllBytes(Server.MapPath("/ASPNETCHAT/sound.au"));
But this will only work for .wav files. I'll try to find a solution for a .au file.
Thomas Daniels 5-Jan-13 11:31am    
It's possible to convert your .au file to a .wav file. There're a lot of audio converters. Here's a list of audio conversion software.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900