NVorbis.OpenTKSupport.OggStream.Play C# (CSharp) Method

Play() public method

public Play ( ) : void
return void
        public void Play()
        {
            var state = AL.GetSourceState(alSourceId);

            switch (state)
            {
                case ALSourceState.Playing: return;
                case ALSourceState.Paused:
                    Resume();
                    return;
            }

            Prepare();

            Logger.Log(LogEvent.Play, this);
            AL.SourcePlay(alSourceId);
            ALHelper.Check();

            Preparing = false;

            OggStreamer.Instance.AddStream(this);
        }

Usage Example

Esempio n. 1
0
        private void PlaySoundThread(string assetName, bool loop)
        {
            string fileName = this.GetAsset (assetName).fileName;
            string ext = fileName.Substring(fileName.LastIndexOf(@".") + 1);

            if (ext == "wav") {
                int channels, bits_per_sample, sample_rate;
                byte[] data = OpenTKUtils.LoadWave (fileName, out channels, out bits_per_sample, out sample_rate);

                int buffer = AL.GenBuffer ();
                int source = AL.GenSource ();
                AL.BufferData (buffer, OpenTKUtils.WaveFormat (channels, bits_per_sample), data, data.Length, sample_rate);

                AL.Source (source, ALSourcei.Buffer, buffer);
                AL.Source (source, ALSourceb.Looping, loop);

                AL.SourcePlay (source);

                int state;

                do {
                    Thread.Sleep (300);
                    AL.GetSource (source, ALGetSourcei.SourceState, out state);
                } while ((ALSourceState)state == ALSourceState.Playing);

                AL.SourceStop (source);
                AL.DeleteSource (source);
                AL.DeleteBuffer (buffer);
            } else if (ext == "ogg") {
                using (var streamer = new OggStreamer ()) {
                    OggStream stream = new OggStream (fileName);
                    stream.Prepare ();
                    stream.Play ();
                }
            } else {
                throw new NotImplementedException($"Support for audio extension '{ext}' is not implemented.");
            }
        }