How to play a file from the network as it downloads? That is, do not wait for its full download, but already play the downloaded part, and even taking into account, to start the download from a certain place, for example, from the second minute, without loading everything that was before that place

This is how it is done when playing a video from Youtube: the download has started, after downloading a certain size of data to play what is, and also start downloading from a new place where the user has indicated a position on the scale

UPDATE: at the moment managed to do the following:

WebResponse response = WebRequest.Create(url).GetResponse(); AsyncStreamCopier asc = new AsyncStreamCopier(input, output,()=>{ output.Position = 0; using (WaveStream blockAlignedStream = new BlockAlignReductionStream( WaveFormatConversionStream.CreatePcmStream( new Mp3FileReader(output)))) { using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback())) { waveOut.Init(blockAlignedStream); waveOut.Play(); while (waveOut.PlaybackState == PlaybackState.Playing) { System.Threading.Thread.Sleep(10); } } } }); asc.Start(); 

//// and class for asynchronous loading

 public class AsyncStreamCopier { private readonly Stream input; private readonly MemoryStream output; private Action onload; private byte[] buffer = new byte[4096]; public AsyncStreamCopier(Stream input, MemoryStream output, Action onload) { this.input = input; this.output = output; this.onload= onload; } public void Start() { GetNextChunk(); } private void GetNextChunk() { input.BeginRead(buffer, 0, buffer.Length, InputReadComplete, null); } private void InputReadComplete(IAsyncResult ar) { int bytesRead = input.EndRead(ar); if (bytesRead == 0) { onload(); return; } output.Write(buffer, 0, bytesRead); Debug.WriteLine(output.Length); GetNextChunk(); } } 

Audio is loaded asynchronously into the MemoryStream (I don’t know why, but it doesn’t work with output of the Stream type), then follow this answer-question https://stackoverflow.com/questions/184683/play-audio-from-a-stream-using- c-sharp

we do the conversion of the stream into a reproducible format and reproducible.

There is not a few important step: to reproduce it when the MemoryStream still being replenished. How to do this?

  • Well, if there is a streaming decoder, it is supposed to produce a stream of audio data as it receives mp3. - VladD
  • Sample code?! ?? - Ni55aN

0