Exemplo n.º 1
0
        public AudioStreamPlayer(AudioStream audioStream, AudioSource audioSource, int buffersize, int buffercount)
        {
            if (audioStream == null)
            {
                throw new ArgumentNullException("audioStream");
            }
            if (audioSource == null)
            {
                throw new ArgumentNullException("audioSource");
            }
            if (buffersize <= 0)
            {
                throw new ArgumentOutOfRangeException("buffersize", "the buffer's size must be greater then 0");
            }
            if (buffercount <= 0)
            {
                throw new ArgumentOutOfRangeException("buffercount", "the buffercount must be greater then 0");
            }
            if (Environment.OSVersion.Platform != PlatformID.Unix && !audioSource.IsValid)
            {
                throw new ArgumentException("The audioSource must be a valid source", "audioSource");
            }

            this.emptyBuffers = new Queue<AudioBuffer>();
            this.stream = audioStream;
            this.source = audioSource;
            this.buffer = new byte[buffersize];
            this.source.Stop();
            OpenAlException.CheckAl();
            buffers = AudioBuffer.CreateBuffers(buffercount);
            for (int pos = 0; pos < buffercount; ++pos)
            {
                FillBuffer(buffers[pos]);
            }
            audioSource.EnqueueBufferRange(buffers);
        }
Exemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!disposed)
                {
                    if (source.IsValid)
                    {
                        source.Clear();
                    }

                    AudioBuffer.ReleaseBuffers(buffers);
                    stream.Close();
                    stream = null;
                    buffer = null;
                    disposed = true;
                }
            }
        }