This project has moved. For the latest updates, please go here.

network streaming

Dec 2, 2013 at 4:05 AM
hi....

I am sorry. My English is poor.

Is it possible to perform a network streaming playback of ogg?

Can download the ogg file, and at the same time playing?
Coordinator
Dec 3, 2013 at 5:44 PM
VorbisReader has a constructor that allows you to pass in any Stream (whether FileStream or otherwise), so you can pass in a NetworkStream and it'll work.

For your scenario, I would create a custom Stream implementation that wraps a NetworkStream and does your buffering / file writing for you. It would also need to be smart enough to indicate to your playback code that it needs to fill the buffer up (so the playback code can wait / pause). Then you can pass the wrapper to VorbisReader and let the wrapper provide the data from the file. It won't be a simple class, but it should work quite well.

Good luck!
Dec 4, 2013 at 1:34 AM
Edited Dec 4, 2013 at 1:46 AM
hi....

I want to play by dividing the ogg file of one.

It tries to play a file that it does not recognize the end time.

My source...

var fs = File.Open(@"C:\Users\scoop\Downloads\oggsource\TestFiles\3test.ogg", FileMode.Open);
byte[] b = new byte[fs.Length];
double temp = fs.Length;
int idx=0, Oldidx = 0;

ms = new MemoryStream();

while (temp > 0)
{
ch = fs.ReadByte();

if (ch == 'O')
{
    b[idx] = (byte)ch;
    idx++;
    temp--;
    ch = fs.ReadByte();
    if (ch == 'g')
    {
        b[idx] = (byte)ch;
        idx++;
        temp--;
        ch = fs.ReadByte();
        if (ch == 'g')
        {
            b[idx] = (byte)ch;
            idx++;
            temp--;
            ch = fs.ReadByte();
            if (ch == 'S')
            {
                b[idx] = (byte)ch;
                temp--;
                idx++;

                if (idx > 17117)
                {
                    ms = new MemoryStream((idx - 4)-Oldidx);
                    ms.Write(b, Oldidx, idx-4);
                    ms.Seek(0, SeekOrigin.Begin);

                    ogg = new VorbisWaveReader(ms);
                    output = new DirectSoundOut();
                    output.Init(new WaveChannel32(ogg));
                    output.Play();                                    
                    Oldidx = idx;
                    ms = new MemoryStream();
                }                                
            }
            else
            {
                b[idx] = (byte)ch;
                temp--;
                idx++;
            }
        }
        else
        {
            b[idx] = (byte)ch;
            temp--;
            idx++;
        }
    }
    else
    {
        b[idx] = (byte)ch;
        temp--;
        idx++;
    }
}
else
{
    b[idx] = (byte)ch;
    temp--;
    idx++;
}
}

ogg = new VorbisWaveReader(ms);
output.Init(new WaveChannel32(ogg));
ERROR..
Length = 'ogg.Length' 'System.ArgumentOutOfRangeException' Throw
Coordinator
Dec 4, 2013 at 3:00 AM
I think I see what you're doing... It looks like you concatenated multiple Ogg files together and want to play back each audio stream in the resulting Ogg file. NVorbis theoretically supports that, but may need a little tweaking to make sure it works right. Have you looked at VorbisReader.StreamCount and VorbisReader.SwitchStreams(...)?