Friday

The wave header is corrupt fix Or how to play wav file with System.Media.SoundPlayer in dot.Net C#

1.add this MediaPlayer class
class MediaPlayer
{
System.Media.SoundPlayer soundPlayer;
public MediaPlayer(byte[] buffer)
{
MemoryStream memoryStream = new MemoryStream(buffer, true);
soundPlayer = new System.Media.SoundPlayer(memoryStream);
}
public void Play() {soundPlayer.Play();}
public void Play(byte[] buffer)
{
soundPlayer.Stream.Seek(0, SeekOrigin.Begin);
soundPlayer.Stream.Write(buffer, 0, buffer.Length);
soundPlayer.Play();
}
}

2. Then file playing procedure will be looking like this:
private void PlayMyFile()
{
string file1 = @"c:\sample.wav";
List<byte> soundBytes = new List<byte>(File.ReadAllBytes(file1));
//create media player loading the first half of the sound file
MediaPlayer mPlayer = new MediaPlayer(soundBytes.ToArray());
//begin playing the file
mPlayer.Play();
}

more...

3 comments:

Joshua said...

Outstanding! Worked like a champ. Thanks so much for sharing this solution!!

shijin mk said...

its working fine...thnx dear

Anonymous said...

Hi,


It's not working for arabic langauage.

It gives me "The wave header is corrupt." error.
Can any one help me for this.

Ruchi

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...