I've got a DLink web cam (DCS-932L) that stream video and audio via http.
The video is mjpeg (motion jpeg) while audio is 16 bit PCM wav audio in mono.
I'm able to read the show the video stream fine, but I'm having issues with the audio. According to the received headers the audio file is only 30 seconds long, but that is false as the camera continues to send data for ever (checked with wget).
Both NAudio, VLC, windows media player etc all stop after 30 seconds as the wav headers say they should. Anyone know of a way to make NAudio discard the length property of the stream header? Or any other library that I can use that handles this?
The code I use today that plays 30 seconds is:
public void PlayWaveFromUrl(string url)
{
new Thread(delegate(object o)
{
var req = WebRequest.Create(url);
req.Credentials = GetCredential(url);
req.PreAuthenticate = true;
var response = req.GetResponse();
using (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;
ms.Position = ms.Length;
ms.Write(buffer, 0, read);
ms.Position = pos;
}
}
}).Start();
// Pre-buffering some data to allow NAudio to start playing
while (ms.Length < 65536 * 10)
Thread.Sleep(1000);
ms.Position = 0;
using (WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new WaveFileReader(ms))))
{
using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
{
waveOut.Init(blockAlignedStream);
waveOut.Play();
while (waveOut.PlaybackState == PlaybackState.Playing)
{
System.Threading.Thread.Sleep(100);
}
}
}
}