Пример #1
0
 public void Dispose()
 {
     if (SoundInstance != null && !SoundInstance.IsDisposed)
     {
         if (SoundInstance.State != SoundState.Stopped)
             SoundInstance.Stop();
         SoundInstance.Dispose();
     }
     if (Sound != null && !Sound.IsDisposed)
         Sound.Dispose();
     if (Emitter != null)
         Emitter = null;
 }
Пример #2
0
        public void Initialize()
        {
            Emitter = null;

            if (Sound == null)
                return;

            if (SoundInstance != null && !SoundInstance.IsDisposed)
            {
                if (SoundInstance.State != SoundState.Stopped)
                    SoundInstance.Stop();
                SoundInstance.Dispose();
            }

            SoundInstance = Sound.CreateInstance();
            SoundInstance.Volume = 0f;
            SoundInstance.Pan = 0f;
            SoundInstance.Pitch = 0f;
        }
Пример #3
0
        public void Play3D(string soundName, bool loop, ISound3DEmitter emitter)
        {
            if (string.IsNullOrEmpty(soundName))
                throw new SoundManagerException("the sound name is null or empty");

            AudioSound sound = _sounds.FirstOrDefault(x => string.Equals(x.Name, soundName));
            if (sound == null)
                throw new SoundManagerException(string.Format("the sound \"{0}\" is not registered!", soundName));

            switch (sound.SoundInstance.State)
            {
                case SoundState.Playing: return;
                case SoundState.Stopped:
                    sound.Initialize();
                    sound.Emitter = emitter;
                    sound.SoundInstance.IsLooped = loop;
                    sound.SoundInstance.Play();
                    SoundPlayedEventDispatcher(new SoundPlayedEventArgs(soundName));
                    break;
                case SoundState.Paused:
                    sound.SoundInstance.Resume();
                    SoundResumedEventDispatcher(new SoundResumedEventArgs(soundName));
                    break;
            }
        }