Hello,
I would like to play a sound. In fact i created the samples by my own, and put them in a table. Now i would like to play it. But i only found some things allowing to play wav files for exemple.
I specify that i DON'T want to store it in a wav file before, it has to be quick and i dont want to create a file on my hard disk, i only want to play my sound.
If any of you have a solution, i would be grateful.
Loading
AnttiPosted Feb 7, 2006, 7:05 AM
Try this approach:
//GetMySoundData could be the place where you
byte[] soundBuffer = GetMySoundData();//create your sound data
//create memory stream that is used to read the buffer
System.IO.MemoryStream soundStream = new System.IO.MemoryStream(soundBuffer);
//now intialize the player
System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundStream);
try
{
//play sound directly from memory stream
player.Play();
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
}
Hope that helps. I haven't got time to test this. It compiles on C# 2.0. You just have to make sure that the data in the buffer is formatted correclty. If you get that working, please let me know:)