0

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!

1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Jakpot
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.