/// <summary>
        /// Creates a new SoundPlayer instance from a string,
        /// for playing MP3 music.
        /// </summary>
        /// <param name="MP3Sound">The name of an MP3 to play, or the path of a file to play if called by a test.</param>
        public SoundPlayer(string MP3Sound, bool LoopIt = true)
        {
            MP3File MP3;

            if (FileManager.Instance.IsInitialized) //Only used by Files.Tests!
            {
                MP3 = (MP3File)FileManager.Instance.GetMusic(MP3Sound);
            }
            else
            {
                MP3 = new MP3File(MP3Sound);
            }

            /*DynamicSoundEffectInstance Instance = new DynamicSoundEffectInstance((int)MP3.GetSampleRate(), AudioChannels.Stereo);
             * Instance.BufferNeeded += Instance_BufferNeeded;*/

            m_ASound        = new ActiveSound();
            m_ASound.MP3    = MP3;
            m_ASound.LoopIt = LoopIt;
            //m_ASound.DynInstance = Instance;

            if (!FileManager.IsLinux)
            {
                m_ASound.PlayTimer          = new System.Timers.Timer();
                m_ASound.PlayTimer.Interval = 250;
                m_ASound.PlayTimer.Elapsed += PlayTimer_Elapsed;
                m_ASound.PlayTimer.Start();

                m_StreamingTask = new Task(new Action(ReadFromStream));
                m_PlaybackState = StreamingPlaybackState.Buffering;
                m_StreamingTask.Start();
            }
        }
Exemple #2
0
        /// <summary>
        /// Starts playing a sound.
        /// </summary>
        /// <param name="WavData">The wav data for this sound.</param>
        /// <param name="SampleRate">The sample rate of the data.</param>
        /// <param name="LoopIt">Wether or not to loop the sound.</param>
        /// <param name="FadeOut">Should this sound fade out?</param>
        public static void PlaySound(byte[] WavData, uint SoundID, uint SampleRate, bool LoopIt = false,
                                     bool FadeOut = false)
        {
            if (m_ActiveSounds.ContainsKey(SoundID))
            {
                m_ActiveSounds[SoundID].Instance.Play();
            }
            else
            {
                SoundEffect         Efx  = new SoundEffect(WavData, (int)SampleRate, AudioChannels.Stereo);
                SoundEffectInstance Inst = Efx.CreateInstance();

                ActiveSound ASound = new ActiveSound();
                ASound.Instance = Inst;
                if (FadeOut)
                {
                    ASound.FadeOut = true;
                }

                m_ActiveSounds.Add(SoundID, ASound);

                if (LoopIt)
                {
                    Inst.IsLooped = true;
                }

                Inst.Play();
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a new SoundPlayer instance.
        /// </summary>
        /// <param name="DecompressedWavData">The decompressed wav data that makes up the sound.</param>
        /// <param name="SampleRate">The sample rate of the sound to play.</param>
        public SoundPlayer(byte[] DecompressedWavData, uint SampleRate)
        {
            SoundEffect         Efx      = new SoundEffect(DecompressedWavData, (int)SampleRate, AudioChannels.Stereo);
            SoundEffectInstance Instance = Efx.CreateInstance();

            m_ASound          = new ActiveSound();
            m_ASound.Instance = Instance;
        }
Exemple #4
0
        /// <summary>
        /// Creates a new SoundPlayer instance from a string,
        /// for playing MP3 music.
        /// </summary>
        /// <param name="MP3Sound">The name of an MP3 to play.</param>
        public SoundPlayer(string MP3Sound, bool LoopIt = true)
        {
            MP3File MP3 = (MP3File)FileManager.GetMusic(MP3Sound);
            DynamicSoundEffectInstance Instance = new DynamicSoundEffectInstance((int)MP3.GetSampleRate(), AudioChannels.Stereo);

            Instance.BufferNeeded += Instance_BufferNeeded;

            m_ASound             = new ActiveSound();
            m_ASound.MP3         = MP3;
            m_ASound.LoopIt      = LoopIt;
            m_ASound.DynInstance = Instance;
        }