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:
Outstanding! Worked like a champ. Thanks so much for sharing this solution!!
its working fine...thnx dear
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
Post a Comment