Beispiel #1
0
        public void Play(byte track, bool looping)
        {
            if (_noAudio == false)
            {
                trackid   = track.ToString("00");
                trackpath = string.Format("{0}/{1}/music/track{2}.ogg", qparam.globalbasedir, qparam.globalgameid, trackid);
#if DEBUG
                Console.WriteLine("DEBUG: track path:{0} ", trackpath);
#endif
                try
                {
                    _isLooping = looping;
                    if (oggStream != null)
                    {
                        oggStream.Stop();
                    }
                    oggStream          = new OggStream(trackpath, 3);
                    oggStream.IsLooped = looping;
                    oggStream.Play();
                    oggStream.Volume = _Volume;
                    _noPlayback      = false;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Could not find or play {0}", trackpath);
                    _noPlayback = true;
                    //throw;
                }
            }
        }
Beispiel #2
0
        public void SetMusic(string se, bool looping)
        {
            float volume = game.settings.musVolume;

            if (game.settings.mutedMusic)
            {
                volume = 0;
            }
            if (File.Exists(game.Content.RootDirectory + game.PathSeperator + "Music" + game.PathSeperator + se + ".ogg"))
            {
                if (currentMusic == se)
                {
                    return;
                }
                currentMusic = se;
                if (music != null)
                {
                    music.Stop();
                }
            }
            else
            {
                currentMusic = "";
                music.Stop();
                Console.WriteLine("PANIC: MUSIC FILE " + se + " NOT FOUND");
                return;
            }
            if (se != currentMusic || music == null)
            {
                if (music != null)
                {
                    music.Stop();
                    music.Dispose();
                    music = null;
                }
                music          = new OggStream(game.Content.RootDirectory + game.PathSeperator + "Music" + game.PathSeperator + se + ".ogg");
                music.IsLooped = looping;
                music.Volume   = volume;
                music.Play();
                currentMusic = se;
            }
            else
            {
                if (music.IsFinished())
                {
                    music.Stop();
                    music.Dispose();
                    music          = null;
                    music          = new OggStream(game.Content.RootDirectory + game.PathSeperator + "Music" + game.PathSeperator + se + ".ogg");
                    music.IsLooped = looping;
                    music.Volume   = volume;
                    music.Play();
                    currentMusic = se;
                }
            }
        }
Beispiel #3
0
 public void Play()
 {
     try
     {
         _stream.Play();
     }
     catch (InvalidDataException)
     {
         Stop();
         Play();
     }
 }
Beispiel #4
0
        internal void Play(TimeSpan?startPosition)
        {
            if (stream == null)
            {
                return;
            }

            stream.Play();
            if (startPosition != null)
            {
                stream.SeekToPosition((TimeSpan)startPosition);
            }

            _playCount++;
        }
Beispiel #5
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.");
            }
        }
Beispiel #6
0
            protected override void OnStart()
            {
                while (!IsCancelled)
                {
                    lock (queue)
                    {
                        var item = queue.Count > 0 ? queue.Peek() : null;
                        if (item != null && item.Value != null)
                        {
                            queue.Dequeue();

                            var audio = item.Value.GetLayer <AudioLayer>();
                            if (audio != null)
                            {
                                var ms        = new MemoryStream(audio.Bytes);
                                var oggStream = new OggStream(ms);
                                oggStream.Play();
                            }
                        }
                        Monitor.Wait(queue, TimeSpan.FromMilliseconds(100));
                    }
                }
            }
Beispiel #7
0
 internal void Play()
 {
     stream.Play();
     _playCount++;
 }