954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Playing wave files from stream

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!

Jakpot
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 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

Jakpot
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: