Hi, I have to design a program that plays sounds (from WAV files). I have to create a wav and play it. Once it finishes I have to change the contents of that wave file and play it again. It is like playing a wave file that is constantly changing. I thought of creating a stream but the problem is when i edit that stream (using ms.Postion and ms.WriteByte), an error occurs saying that "the wave header file is corrupt". The following is my code:

MemoryStream ms = new MemoryStream(Sample1);
SoundPlayer myPlayer = new SoundPlayer(ms);
myPlayer.Play();                             //Wav file plays

for (int x = 0; x < 50; x++)
{
     ms.Position = 44 + x;
     ms.WriteByte(10);
}

myPlayer.Stop();
myPlayer.Play();                 //Header file corrupt

Is there maybe another way I can loop a stream, and change its contents while it is looping. For example, the stream is looping Sound1 and whenever a button is pressed, the stream's content is changed to play Sound2.

Thank you!

Now i have managed to change the contents of the stream by changing the contents of the array 'Sample1'. The problem is that when i run the sound player (ie. myPlayer.PlayLooping), I can only hear the contents of the original stream. I cannot find a way to set the sound player to play the new stream. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.