Hi
I want Read and play a sound file in c# as byte by byte. this bytes that reading, place in array of byte by lengh 500000. Now i want play this array! Please help me.
System.IO.FileStream fs = new System.IO.FileStream(@"c:\a.wav", System.IO.FileMode.Open);
byte[] buffer = new byte[500000];
byte[] buffer = new byte[500000];
fs.Read(buffer, 0, buffer.Length);
system.IO.Stream s = new system.IO.MemoryStream(buffer);
System.Media.SoundPlayer spPlayer = new System.Media.SoundPlayer(s);
spPlayer.Stream = s;
spPlayer.Stream.Position = 0;
spPlayer.Play();
Please Help what is Problem of my code?
Read & Play a Sound file
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

FroglegRank #1,020 · 1.9K reputationPosted Jan 24, 2012, 10:30 PM EST
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
namespace SimpleSound
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SoundPlayer mySound = new SoundPlayer(@"C:\a.wav");
mySound.Play();
}
}
}
yaquza yaquza13 reputationPosted Jan 25, 2012, 12:04 AM EST