.net - SoundPlayer and MemoryStream in C# -


i build sample program select wav file, can play selected file 2x speed or 4x speed

the code of previous app :

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.io; namespace playwave {     public partial class form1 : form     {         private byte[] b;         private openfiledialog open;         public form1()         {             open = new openfiledialog();             open.filter = "wav sound file (*.wav)|*.wav";             initializecomponent();         }          private void selectfile_click(object sender, eventargs e)         {             if (!(open.showdialog() == dialogresult.ok))             {                 return;             }         }          private void twox_click(object sender, eventargs e)         {             b = file.readallbytes(open.filename);             int samplerate = bitconverter.toint32(b, 24) * 2;             array.copy(bitconverter.getbytes(samplerate), 0, b, 24, 4);             using (system.media.soundplayer sp = new system.media.soundplayer(new memorystream(b)))             {                 sp.play();             }         }          private void fourx_click(object sender, eventargs e)         {             b = file.readallbytes(open.filename);             int samplerate = bitconverter.toint32(b, 24) * 4;             array.copy(bitconverter.getbytes(samplerate), 0, b, 24, 4);             using (system.media.soundplayer sp = new system.media.soundplayer(new memorystream(b)))             {                 sp.play();             }         }     } } 

above, changed value of (25,26,27,28) bytes of file represent sample rate of wave file save changes , play file using system.media.soundplayer , memorystream .

my problem when clicked on button plays file in 2x speed on 3 clicks , program stop , error message appaer , can 1 tell me why ?


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -