Deleting played bytes in blockedalginstream

Mar 21, 2011 at 5:06 PM

I have programmed a webradio but there is still on problem.

I am writing every second to to my blockedalginstream. It is working perfectly everything, but if the programm runs 4 a few houres it gets laggy because the stream gets a length about 233.000.000bytes and more.


So how can i delete a part of my stream?


Please help me :(

Mar 21, 2011 at 5:08 PM

have a look at the suggestion in this post:


Mar 23, 2011 at 7:41 AM
Edited Mar 24, 2011 at 2:29 PM

thanks a lot i had a look on that and looks nice but i can t find BufferedWaveProvider.

you may help me :)

EDIT: @ markheath ist es möglich, dass du deutsch kannst dann könnte ich nähmlich besser erklären was mein problem ist... weil hier: steht dein name bei autor :)


EDIT2: found it i had an old version of naudio >.<

Mar 25, 2011 at 3:29 PM
Edited Mar 27, 2011 at 12:57 PM

ok i tried but it doesn t help me... now here is my basic code ( it is a lot more but i cut out the important things )


  private Stream ms = new MemoryStream();
public void PlayMp3FromUrl(string url)
new Thread(delegate(object o)
var response = WebRequest.Create(url).GetResponse();
(var stream = response.GetResponseStream())
byte[] buffer = new byte[65536]; // 64KB chunks
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
var pos = ms.Position;
.Position = ms.Length;
.Write(buffer, 0, read);
.Position = pos;

// Pre-buffering some data to allow NAudio to start playing
while (ms.Length < 65536*10)

.Position = 0;
(WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(ms))))
(WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
while (waveOut.PlaybackState == PlaybackState.Playing)

now my problem is the blockAlignedStream gets 2 big
also the the ms

so is there a posibility to free the played bytes?

here is a screen of the problem: this 9.240 k getting bigger up to 250k and more :(

because the problem is a need to decode the mp3 stream and this bufferedwaveprovider doesn t support so i have to decode with a mp3filereader but this would be also big

because of the mp3filereader

here is an example:

OpenFileDialog ofn = new OpenFileDialog();
            WaveOut OutPut;
            Mp3FileReader mp3read = new Mp3FileReader(ofn.FileName);
            int read = 0;
            byte[] buffer = new byte[65536];
            BufferedWaveProvider wp = new BufferedWaveProvider(new WaveFormat());
            wp.DiscardOverrunedBuffers = true;
            while((read = WaveFormatConversionStream.CreatePcmStream(mp3read).Read(buffer,0,buffer.Length)) > 0){
                wp.AddSamples(buffer, 0, buffer.Length);
            OutPut = new WaveOut(WaveCallbackInfo.FunctionCallback());

and the last line: Console.WriteLine(mp3read.Length); Says that it is tooo long :( so what to do with this?
Mar 30, 2011 at 9:35 AM

you would need to decompress the MP3 file frame by frame, and add each decompressed frame to the buffered wave provider


Mar 30, 2011 at 7:49 PM

thanks i will try