public void StopPlaying()
 {
     if (_sound != null && !_sound.Finished)
     {
         _sound.Stop();
     }
     if (IsPlaying)
     {
         _player.Stop();
     }
     try
     {
         _engine.RemoveAllSoundSources();
     }
     catch (Exception)
     {
         // We'll just ignore any errors on stopping the sounds (they probably aren't playing).
     }
     _engine.StopAllSounds();
     if (_sound != null)
     {
         _sound.Dispose();
     }
     _sound = null;
 }
示例#2
0
        /// <summary>
        /// Nice sound if the button has been pressed. by M.R.
        /// </summary>
        private void PlayButtonSound()
        {
            ISound snd = game.Sounds.CreateSound("Button");

            snd.Play();
            snd.Dispose();
        }
示例#3
0
        public void Stop()
        {
            _timer.Stop();
            if (_currentPlayback != null)
            {
                _currentPlayback.Stop();
                _currentPlayback.Dispose();
                _currentPlayback = null;
            }

            TrackDuration  = TimeSpan.FromSeconds(0);
            SampleRate     = 0;
            BytesPerSecond = 0;
            Channels       = 0;
            NotifyPlayBackStateChanged();
        }
示例#4
0
        /// <summary>
        /// Executes if the player has finished the level
        /// </summary>
        public void Finish()
        {
            isFinish = true;

            // Stop weapon fireing
            Weapons.PrimaryWeapon.EndFire();
            // Weapons.SecondaryWeapon.EndFire();

            if (game.World.Finish == null)
            {
                // Create finish object
                game.World.Finish = new Finish(game);
                game.World.AddObject(game.World.Finish);
                //game.GameStates.Gameplayed = true;
                // Set the flag position
                Vector3 v = Velocity;
                if (Velocity.Length() != 0)
                {
                    v.Normalize();
                }
                game.World.Finish.LocalPosition = Vector3.Add(LocalPosition, v * 160);
                game.World.Finish.LocalRotation = Quaternion.CreateFromAxisAngle(v, 45);

                // Slow down the speed of the player
                this.Velocity = Vector3.Zero;
            }
            if (hurryUpEfx != null)
            {
                hurryUpEfx.Loop = false;
                hurryUpEfx.Stop();
                hurryUpEfx.Dispose();
            }
            if (meshSoundEfx != null)
            {
                meshSoundEfx.Loop = false;
                meshSoundEfx.Stop();
                meshSoundEfx.Dispose();
            }
            Enabled = false;
            game.GameStates.Gameplayed = true;
            //if (Helper.Lock("DIEorDIE", TimeSpan.FromSeconds(7)))
            //{
            // game.GameStates.Reset();
            //game.GameStates.Gameplayed = true;
            // game.GameStates.SetStateMenu();
            //}
        }
示例#5
0
        public override void Dispose()
        {
            if (sound != null)
            {
                sound.Dispose();
            }

            base.Dispose();
        }
示例#6
0
        public void Dispose()
        {
            if (player?.PlaybackState == PlaybackState.Playing)
            {
                player?.Stop();
            }

            reader?.Dispose();
            player?.Dispose();
        }
示例#7
0
 public override void Explode()
 {
     base.Explode();
     // For audio and mesh animation by M.R.
     if (modelAnimationPart != null)
     {
         meshSoundEfx.Stop();
         meshSoundEfx.Dispose();
     }
     // ------------------------------------
     Visible = false;
 }
示例#8
0
        public void Play()
        {
            if (IsRecording)
            {
                throw new ApplicationException("Can't play while recording.");
            }

            if (_sound != null)
            {
                _engine.StopAllSounds();
            }

            if (!File.Exists(_path))
            {
                throw new FileNotFoundException("Could not find sound file", _path);
            }

            //turns out, the silly engine will keep playing the same recording, even
            //after we've chaned the contents of the file or even delete it.
            //so, we need to make a new engine.
            //   NO   _sound = _engine.Play2D(path, false);

            var engine = new IrrKlang.ISoundEngine();


            // we have to read it into memory and then play from memory,
            // because the built-in Irrklang play from file function keeps
            // the file open and locked
            byte[] audioData = File.ReadAllBytes(_path);                //REVIEW: will this leak?
            _soundSource = engine.AddSoundSourceFromMemory(audioData, _path);
            if (_sound != null)
            {
                _sound.Dispose();
            }
            _sound = engine.Play2D(_soundSource, false, false, false);
            _sound.setSoundStopEventReceiver(_irrklangEventProxy, engine);
        }
示例#9
0
        public static void stopBgm()
        {
            if (musica != null)
            {
                musica.Stop();
                musica.Dispose();
                musica = null;
            }


            if (mainOutput != null)
            {
                //mainOutput.Stop();
            }
        }
示例#10
0
        //remove stuff
        public void RemoveAmbientSound(ISound sound)
        {
            if (sound.Type != SoundType.AmbientSound)
            {
                throw new ArgumentException("sound must be an ambient sound type");
            }

            if (!_ambientSounds.Contains(sound))
            {
                throw new ArgumentException("sound does not exist in the collection");
            }

            _ambientSounds.Remove(sound);

            sound.Dispose();
        }
示例#11
0
        public void RemoveMusicBed(ISound sound)
        {
            if (sound.Type != SoundType.MusicBed)
            {
                throw new ArgumentException("sound must be a music bed");
            }

            if (!_musicBeds.Contains(sound))
            {
                throw new ArgumentException("sound does not exist in the collection");
            }

            _musicBeds.Remove(sound);

            sound.Dispose();
        }
示例#12
0
        public void RemoveSoundEffect(ISound sound)
        {
            if (sound.Type != SoundType.SoundEffect)
            {
                throw new ArgumentException("sound must be a sound effect");
            }

            if (!_soundEffects.Contains(sound))
            {
                throw new ArgumentException("sound does not exist in the collection");
            }

            _soundEffects.Remove(sound);

            sound.Dispose();
        }
示例#13
0
        public void playNext()
        {
            if (currentSoundIndex < playlist.Count)
            {
                ISound currentSound = playlist.ElementAt(currentSoundIndex).Value;
                currentSound.Paused = true;
                currentSound.Dispose();
            }

            currentSoundIndex++;
            if (currentSoundIndex < playlist.Count)
            {
                ISound currentSound = playlist.ElementAt(currentSoundIndex).Value;
                currentSound.PlayPosition = 0;
                currentSound.Paused       = false;
            }
        }
示例#14
0
 public void DisposeHandle()
 {
     if (MediaControl != null)
     {
         MediaControl.Stop();
     }
     timer1.Stop();
     soundengine.StopAllSounds();
     if (pictureBox1.Image != null)
     {
         pictureBox1.Image.Dispose();
     }
     CleanUp();
     if (currentSound != null)
     {
         currentSound.Dispose();
     }
     tlp.Visible = false;
 }
示例#15
0
        public void Stop()
        {
            lock (this)
            {
                if (Finished)
                {
                    return;
                }
                Finished = true;
            }

            Playback?.Stop();
            Playback?.Dispose();

            //notify listeners
            PlaybackFinished?.Invoke(this, new ISoundPlaybackService.PlaybackEventArgs(
                                         sound: this.Sound,
                                         fromStop: true
                                         ));
        }
示例#16
0
        public int getLength(string soundName)
        {
            int length = 0;

            if (playlist.ContainsKey(soundName))
            {
                length = (int)playlist[soundName].PlayLength;
            }
            else if (File.Exists(FullPrefix + soundName + ".wav"))
            {
                ISound sound = engine.Play2D(FullPrefix + soundName + ".wav");
                length       = (int)sound.PlayLength;
                sound.Paused = true;
                sound.Dispose();
            }
            else
            {
                Tools.log("Try to get length on undefined music file : " + FullPrefix + soundName + ".wav");
            }

            return(length);
        }
示例#17
0
        public void Play(string soundName)
        {
            try
            {
                if (aguante >= 30)
                {
                    return;
                }

                //aguante++;
                //if (output[direccion[soundName]].PlaybackState == PlaybackState.Playing)
                // {
                if (soundName.EndsWith(".wav") == true)
                {
                    //playWithMedia(soundName);
                    //return;
                }
                ISound sfx = controlador.Play2D(soundName);
                sfx.Dispose();

                return;


                WaveStream        auxoxo = CreateInputStreamReturnable(soundName);
                WaveMixerStream32 extrr  = new WaveMixerStream32();
                extrr.AutoStop = true;
                extrr.AddInputStream(auxoxo);

                auxoxo.Position = 0;


                DirectSoundOut auxili = new DirectSoundOut();


                diccionarioLoco.Add(auxili, auxoxo);
                diccionarioReLocoMixer.Add(auxili, extrr);

                auxili.PlaybackStopped += new EventHandler(auxili_PlaybackStopped);


                auxili.Init(extrr);
                auxili.Play();


                /*auxili.Dispose();
                 *  auxili.Stop();
                 *
                 *
                 *  //error("dentro del if");
                 *
                 * //}
                 * else
                 * {
                 *  mainStreams[direccion[soundName]].Position = 0;
                 *  mixeador[direccion[soundName]].AddInputStream(mainStreams[direccion[soundName]]);
                 *
                 *  output[direccion[soundName]].Init(mixeador[direccion[soundName]]);
                 *
                 *  output[direccion[soundName]].Play();
                 *
                 *
                 *  output[direccion[soundName]].Init(mainStreams[direccion[soundName]]);
                 *  output[direccion[soundName]].Play();
                 *
                 *  output[direccion[soundName]].Dispose();
                 *
                 *
                 *  error("no estoy en el if ");
                 *
                 * }
                 *
                 * output[direccion[soundName]].PlaybackStopped += new EventHandler(MainPlayer_PlaybackStopped);
                 *
                 */
            }
            catch (Exception e)
            {
                if (error != null)
                {
                    error(e.Message + " error en play " + direccion[soundName]);
                }
            }
        }
 protected override void OnDisappearing()
 {
     patcher.Dispose();
     sound.Dispose();
     base.OnDisappearing();
 }
示例#19
0
 public void Dispose()
 {
     stream.Dispose();
     engine.Dispose();
 }
 public void Remove(ISound sound)
 {
     sound.Stop();
     sound.Dispose();
     _activeSounds.Remove(sound);
 }
        // 3D Sound stuff only

        /*public void ProcessSound(Vector3 sourcePosition)
         * {
         *  if (Sound != null && !Sound.Finished)
         *  {
         *      Sound.MaxDistance = MaximumDistance;
         *      Sound.MinDistance = MinimumDistance;
         *      Vector3D sourcePos = SoundHelperIK.Vector3ToVector3D(GameplayCamera.GetOffsetFromWorldCoords(sourcePosition));
         *      Sound.Position = sourcePos;
         *  }
         * }
         *
         * public void SetDistances(float max, float min)
         * {
         *  MaximumDistance = max;
         *  MinimumDistance = min;
         * }*/

        public void Dispose()
        {
            Sound.Stop();
            Sound.Dispose();
            Source.Dispose();
        }
示例#22
0
        private void updateInterruptSounds()
        {
            if (currentInterruptSound == null && DemagoScript.isThereACurrentMission())
            {
                string fileFullPath = "";
                if (Function.Call <Boolean>(Hash.HAS_PED_BEEN_DAMAGED_BY_WEAPON, Game.Player.Character, 0, 2))
                {
                    int next = random.Next(10) + 1;
                    fileFullPath = FullPrefix + "balle" + next + ".wav";
                }
                else
                {
                    if (Function.Call <Boolean>(Hash.HAS_ENTITY_BEEN_DAMAGED_BY_ANY_VEHICLE, Game.Player.Character))
                    {
                        int next = random.Next(8) + 1;
                        fileFullPath = FullPrefix + "voiture" + next + ".wav";
                    }
                    else
                    {
                        if (Function.Call <Boolean>(Hash.HAS_ENTITY_BEEN_DAMAGED_BY_ANY_OBJECT, Game.Player.Character))
                        {
                            int next = random.Next(7) + 1;
                            fileFullPath = FullPrefix + "insulte" + next + ".wav";
                        }
                    }
                }

                if (fileFullPath != "")
                {
                    if (File.Exists(fileFullPath))
                    {
                        if (currentSoundIndex < playlist.Count)
                        {
                            if (!playlist.ElementAt(currentSoundIndex).Key.StartsWith("flic"))
                            {
                                playlist.ElementAt(currentSoundIndex).Value.Paused = true;
                            }
                        }

                        currentInterruptSound = engine.Play2D(fileFullPath);
                        if (currentInterruptSound != null)
                        {
                            currentInterruptSound.Paused = false;
                        }
                        else
                        {
                            Tools.log("just created currentInterruptSound is null");
                        }
                    }
                    else
                    {
                        Tools.log("interruption file doesn't exist" + fileFullPath);
                    }
                }
            }

            if (currentInterruptSound != null && currentInterruptSound.Finished)
            {
                if (currentSoundIndex < playlist.Count)
                {
                    playlist.ElementAt(currentSoundIndex).Value.Paused = false;
                }

                currentInterruptSound.Dispose();
                currentInterruptSound = null;

                Function.Call(Hash.CLEAR_ENTITY_LAST_DAMAGE_ENTITY, Game.Player.Character);
                Function.Call(Hash.CLEAR_ENTITY_LAST_WEAPON_DAMAGE, Game.Player.Character);
            }
        }