Permalink
Browse files

Stream constructor instead of (or in addition to) filename

  • Loading branch information...
1 parent 360fd25 commit 9a14370d649869ab86fdaf905ca232905583e4aa @renaudbedard committed Sep 5, 2012
Showing with 10 additions and 6 deletions.
  1. +10 −6 OggStream/OggStream.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
+using System.IO;
using System.Threading;
using NVorbis;
using OpenTK.Audio.OpenAL;
@@ -45,10 +46,10 @@ public void Dispose()
ThreadFlow currentFlow;
Thread currentThread;
+ Stream underlyingStream;
VorbisReader reader;
bool ready;
- public string Filename { get; private set; }
public bool IsLooped { get; set; }
static OggStream()
@@ -57,10 +58,9 @@ static OggStream()
fxe = new EffectsExtension();
}
- public OggStream(string filename)
+ public OggStream(string filename) : this(File.OpenRead(filename)) { }
+ public OggStream(Stream stream)
{
- Filename = filename;
-
alBufferIds = AL.GenBuffers(BufferCount);
alSourceId = AL.GenSource();
Volume = 1;
@@ -82,12 +82,14 @@ public OggStream(string filename)
LowPassHFGain = 1;
}
- Open(precache: true);
+ underlyingStream = stream;
+ Open(precache: true);
}
void Open(bool precache = false)
{
- reader = new VorbisReader(Filename);
+ underlyingStream.Seek(0, SeekOrigin.Begin);
+ reader = new VorbisReader(underlyingStream, false);
if (precache)
{
@@ -214,6 +216,8 @@ public void Dispose()
Close();
+ underlyingStream.Dispose();
+
AL.DeleteSource(alSourceId);
AL.DeleteBuffers(alBufferIds);

0 comments on commit 9a14370

Please sign in to comment.