Play() public méthode

Gets an internal SoundEffectInstance and plays it.

Play returns false if more SoundEffectInstances are currently playing then the platform allows.

To loop a sound or apply 3D effects, call SoundEffect.CreateInstance() and SoundEffectInstance.Play() instead.

SoundEffectInstances used by SoundEffect.Play() are pooled internally.

public Play ( ) : bool
Résultat bool
Exemple #1
0
        public Ship(Game game, Vector2 PosicaoInicial, Texture2D texture, SoundEffect SoundShip)
            : base(game, PosicaoInicial, texture)
        {
            _game = game;
            ShipSound = SoundShip;
            ShipSound.Play();

            SpriteX = 0;
            SpriteY = 0;
            PosicaoX = (int)PosicaoInicial.X;
            PosicaoY = (int)PosicaoInicial.Y;

            Vida = 100;

            accelReading = new Vector3();
            accelSensor = new Accelerometer();
            accelSensor.ReadingChanged +=
                new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged);
            try
            {
                accelSensor.Start();
                accelActive = true;
            }
            catch (AccelerometerFailedException e)
            {
                accelActive = false;

            }
            catch (UnauthorizedAccessException e)
            {
                accelActive = false;
            }
        }
        /// <summary>
        /// Creates a new explosion
        /// </summary>
        /// <param name="position">The position of the explosion within the game world</param>
        /// <param name="content">A ContentManager to load resources with</param>
        public Explosion2(uint id, Vector2 position, ContentManager content, float scale)
            : base(id)
        {
            this.position = position;

            Scale = scale;

            this.spriteSheet = content.Load<Texture2D>("Spritesheets/explosion");
            explosionSound = content.Load<SoundEffect>("SFX/Blast");
            explosionSound.Play();

            for (int i = 0; i < 12; i++)
            {
                spriteBounds[0] = new Rectangle(134 * i, 0, 134, 134);
            }
            spriteBounds[0] = new Rectangle(0, 0, 134, 134);
            spriteBounds[1] = new Rectangle(134, 0, 134, 134);
            spriteBounds[2] = new Rectangle(268, 0, 134, 134);
            spriteBounds[3] = new Rectangle(402, 0, 134, 134);
            spriteBounds[4] = new Rectangle(536, 0, 134, 134);
            spriteBounds[5] = new Rectangle(670, 0, 134, 134);
            spriteBounds[6] = new Rectangle(804, 0, 134, 134);
            spriteBounds[7] = new Rectangle(938, 0, 134, 134);
            spriteBounds[8] = new Rectangle(1072, 0, 134, 134);
            spriteBounds[9] = new Rectangle(1206, 0, 134, 134);
            spriteBounds[10] = new Rectangle(1340, 0, 134, 134);
            spriteBounds[11] = new Rectangle(1474, 0, 134, 134);

            this.explosionState = 0;
            this.explosionTimer = 0;
        }
Exemple #3
0
 private void PlayRecordedAudio()
 {
     SoundEffect se = new SoundEffect(audio.ToArray(), mic.SampleRate,
     AudioChannels.Stereo);
     se.Play(1.0f, -1.0f, 0.0f);
     btnRecord.IsEnabled = true;
 }
Exemple #4
0
        public static void playSound(string soundName, float volume)
        {
            effect = m_Content.Load<SoundEffect>(soundName);

            if (m_EffectInstance == null)
            {
                m_EffectInstance = effect.CreateInstance();
                effect.Play(volume, 0, 0);
            }
            else
            {
                effect.Play(volume,0,0);
            }

                m_EffectInstance = null;
        }
 private void listenAgainHold(object sender, System.Windows.Input.GestureEventArgs e)
 {
     Thread.Sleep(1500);
     Microphone mic = Microphone.Default;
     SoundEffect soundEffect = new SoundEffect(myMicrophone.streamMicrophone.ToArray(), mic.SampleRate, AudioChannels.Mono);
     myMicrophone.streamMicrophone.Seek(0, System.IO.SeekOrigin.Begin);
     soundEffect.Play(1.0f, 0.0f, 0.0f);
 }
Exemple #6
0
 public void Initialize(Animation anim, int timeOflife, SoundEffect sound)
 {
     this.EffectAnimation = anim;
     this.TimeOfLiving = timeOflife;
     VisualEffectSound = sound;
     Alive = true;
     if (VisualEffectSound != null) VisualEffectSound.Play();
 }
Exemple #7
0
 /// <summary>
 /// Plays specified sound at specified place. It automaticly sets the volume.
 /// </summary>
 /// <param name="sound">The specified sound</param>
 /// <param name="position">The specified position</param>
 public void PlaySound(SoundEffect sound, PositionInTown position)
 {
     if (game.Player.Position.Quarter == position.Quarter)
     {
         float quarterDiagonalLength = (new Vector2(position.Quarter.BitmapSize.Width, position.Quarter.BitmapSize.Height) * TownQuarter.SquareWidth).Length();
         sound.Play(1f- (position.MinimalDistanceTo(game.Player.Position) / quarterDiagonalLength), 0f, 0f);
     }
 }
        /// <summary>
        /// Plays a given song as the background music.
        /// </summary>
        /// <param name="song">The song to play.</param>
        public void Play(SoundEffect sound, float volume)
        {
            if (IsMuted)
                return;

            volume = Math.Min(volume, MaxVolume);
            sound.Play(volume, 0.0f, 0.0f);
        }
Exemple #9
0
 public void playEffect(String soundname, ContentManager content, bool sound)
 {
     if (sound == true)
     {
         effect = content.Load<SoundEffect>(soundname);
         effect.Play();
     }
 }
 public void Collect(Rectangle loc, Level level, SoundEffect pearSound)
 {
     if (loc.Intersects (location) && !collected) {
         level.numCollected++;
         pearSound.Play ();
         collected = true;
     }
 }
Exemple #11
0
 public Explosion(Rectangle box) :
     base (Globals.Content.Load<Texture2D>("Textures/explosion.png"), box)
 {
     time = 200;
     ExplosionList.Add(this);
     sound = Globals.Content.Load<SoundEffect>("Sounds/explosion.wav");
     sound.Play();
 }
        /// <summary>
        /// Constructs a new explosion object
        /// </summary>
        /// <param name="spriteStrip">the sprite strip for the explosion</param>
        /// <param name="x">the x location of the center of the explosion</param>
        /// <param name="y">the y location of the center of the explosion</param>
        public Explosion(Texture2D spriteStrip, int x, int y, SoundEffect explosion)
        {
            // initialize animation to start at frame 0
            currentFrame = 0;

            Initialize(spriteStrip);
            Play(x, y);
            explosion.Play();
        }
 //TODO: play on gsm output device
 public void Play(byte[] packetData)
 {
     lock (SyncObj)
     {
         _soundEffect = new SoundEffect(packetData, _microphone.SampleRate, AudioChannels.Mono);
         _soundEffect.Play();
         //_soundEffect.Dispose();
     }
 }
Exemple #14
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            soundEffect = Content.Load<SoundEffect>("Audio/start");
            soundEffect.Play();
        }
        /// <summary>
        /// Constructs a new explosion object
        /// </summary>
        /// <param name="spriteStrip">the sprite strip for the explosion</param>
        /// <param name="x">the x location of the center of the explosion</param>
        /// <param name="y">the y location of the center of the explosion</param>
        public Explosion(Texture2D spriteStrip, int x, int y, SoundEffect explosionSound)
        {
            // initialize animation to start at frame 0
            currentFrame = 0;

            Initialize(spriteStrip);
            Play(x, y);
            explosionSound.Play();//Without this the explosion sound effect will never start
            
        }
Exemple #16
0
 public void handleCollision(Vector2 collisionVect, SoundEffect playSound)
 {
     if (collisionCD <= 0)
     {
         mVelocity = collisionVect;
         collisionCD = 60;
         playSound.Play();
         mEffect.init();
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="s"></param>
 /// <param name="cat"> Set to null to bypass auto volume settings.</param>
 /// <param name="loop"></param>
 /// <param name="volume"></param>
 /// <param name="pitch"></param>
 /// <param name="pan"></param>
 internal static void PlaySound(SoundEffect s, SoundCategory cat, bool loop = false, float volume = 1, float pitch = 0, float pan = 0)
 {
     if (s == null || s.IsDisposed) return;
     if (cat == SoundCategory.Music)
         volume = Manager.GameSettings.MusicVolume;
     if (cat == SoundCategory.SFX)
         volume = Manager.GameSettings.SFXVolume;
     s.Play(volume, pitch, pan);
     if (loop && !looping.ContainsKey(s))
         looping.Add(s, new SFXData(volume, pitch, pan));
 }
Exemple #18
0
 /// <summary>
 /// Handles the initlization of the SplashObject
 /// </summary>
 public Splash(GraphicsDevice GraphicsDevice, ContentManager Content)
 {
     testAlarm = new Alarm(5.55f);
        testMusic = Content.Load<SoundEffect>("faucetmusic");
        testInstance = testMusic.CreateInstance();
        testInstance.IsLooped = false;
        testMusic.Play(0.1f, 0.0f, 0.0f);
        faucetLogo = Content.Load<Texture2D>("FaucetLogoS_SpriteSheet_strip22.png");
        animationObject = new Animation(new Vector2(60, 41), 0f, 1f, 0f, false);
        animationObject.Load(GraphicsDevice, Content, "FaucetLogoS_SpriteSheet_strip22.png", 22, 8);
 }
Exemple #19
0
 public override void LoadContent()
 {
     base.LoadContent();
     font = content.Load<SpriteFont>("Fonts/Test");
      logo = content.Load<SoundEffect>("Music/Logo");
        // SoundEffectInstance sound = logo.CreateInstance();
      duration = logo.Duration.TotalSeconds;
     logo.Play();
     image = content.Load<Texture2D>(path);
     Image.LoadContent();
 }
Exemple #20
0
 //  TyDo: Create a new projectile that deals less damage than an arrow, but for now just make it the fireball
 //  Attack the target (not homing). Create a new object projectile sent in the direction of target
 //  The new attack code
 public override void Attack(GameObject target, ContentManager content, ProjectileManager projMan)
 {
     this.soundEffect = content.Load<SoundEffect>("fireball.wav");
     soundEffect.Play();
     Vector2 corrected = Vector2.Add(position, new Vector2(16, 16));
     Projectile projectile = new Iceball(corrected, 0, target, 1, 0);
     Vector2 direction = MovementManager.getNormalizedVector(projectile.position, target.position);
     projectile.setDestination(direction, target.position);
     projectile.LoadContent(content);
     projMan.proj.Add(projectile);
     this.animateState = "attack";
     this.animateTime = 0;
 }
Exemple #21
0
        public Level1Screen(Game game, SpriteBatch sB)
            : base(game, sB)
        {
            spriteFont1 = Game.Content.Load<SpriteFont>("Fonts/SF1");
            isActive = true;
            isCompleted = false;
            isintroComplete = false;
            istutorialComplete = false;
            ismovingComplete = false;

            isPlayerLaunched = false;

            screenRectangle = new Rectangle(0, 0, Game1.screenWidth,Game1.screenHeight);

            // set up level content
            iTitle = new TitleObject(game, sB, Game.Content.Load<Texture2D>("Sprites/InfinitelyV2"));
            iTitle.targetPosition = new Vector2(650, 150);
            iTitle.position = -10f*iTitle.targetPosition;

            iiTitle = new TitleObject(game, sB, Game.Content.Load<Texture2D>("Sprites/ImprobableV2"));
            iiTitle.position = GenerateRandomPositionOutside();
            iiTitle.rotation = 0f;
            iiTitle.targetPosition = new Vector2(450, 350);
            iiTitle.targetRotation = 20f * (float)Math.PI;

            iiiTitle = new TitleObject(game, sB, Game.Content.Load<Texture2D>("Sprites/IncertitudeV1"));
            iiiTitle.targetPosition = new Vector2(600, 500);
            iiiTitle.position = -iiiTitle.targetPosition;
            iiiTitle.initialShake = 1f;

            Game.Components.Add(iTitle);
            Game.Components.Add(iiTitle);
            Game.Components.Add(iiiTitle);

            mainPlayer = GameFlowManager.player1;

            mainPlayer.isControllable = false;
            mainPlayer.isMoveable = false;
            mainPlayer.activeTextureID = 1;

            timeCount = 0;

            wall_smack = Game.Content.Load<SoundEffect>("SoundEffects/smack-1");
            toilet_flush = Game.Content.Load<SoundEffect>("SoundEffects/toilet-flush-2");

            SoundEffect.MasterVolume = 0.08f;
            toilet_flush.Play();

            toj = Game.Content.Load<Texture2D>("Sprites/TOJstamp");
        }
Exemple #22
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            map = Content.Load<Texture2D>("BallGame");
            Entity player = new Player(Content.Load<Texture2D>("John front"));
            Entity monster = new Monster(Content.Load<Texture2D>("Monster2"));
            GameTickController.addEntity(player);
            GameTickController.addEntity(monster);
            Fireball.FireballImg = Content.Load<Texture2D>("fireball");

            backgroundMusic = Content.Load<SoundEffect>("Paradise Town");
            backgroundMusic.Play();
        }
Exemple #23
0
        public override void Initialize()
        {
            base.Initialize();

            font = Game.Content.Load<SpriteFont>("PixelFont" + Game.DefaultFontSize);
            countSound = Game.Content.Load<SoundEffect>("count");
            startSound = Game.Content.Load<SoundEffect>("start");

            // TextLabel
            label = new TextLabel(Game)
            {
                Font = font,
                Text = "",
                Color = Color.Black,
            };
            components.Add(label);

            // setup countdown animation
            Action<int> updateCount = count =>
            {
                label.Text = count.ToString();
                countSound.Play(0.5f, 0, 0);
            };
            animProvider.CreateChain()
                .Wait(1000)
                .Then(() => label.Text = "READY")
                .Wait(2000)
                .Then(() => updateCount(3))
                .Blink(label, 200, 5)
                .Then(() => updateCount(2))
                .Blink(label, 200, 5)
                .Then(() => updateCount(1))
                .Blink(label, 200, 5)
                .Then(() =>
                {
                    label.Text = "START!";
                    startSound.Play(0.5f, 0, 0);
                })
                .Blink(label, 200, 5)
                .Then(() =>
                {
                    if (Started != null)
                    {
                        Started(this, EventArgs.Empty);
                    }
                    Game.SceneManager.Pop();
                });
        }
Exemple #24
0
 public override void LoadContent()
 {
     base.LoadContent();
     XmlManager<Player> playerLoader = new XmlManager<Player>();
     XmlManager<Map> mapLoader = new XmlManager<Map>();
     texturebg = content.Load<Texture2D>("Images/paper");
     font = content.Load<SpriteFont>("Fonts/Test");
     player = playerLoader.Load("Load/Game/Player.xml");
     map = mapLoader.Load("Load/Game/Maps/Map_Two.xml");
     map.LoadContent();
     player.LoadContent();
     music = content.Load<SoundEffect>("Music/sad");
     paper = content.Load<SoundEffect>("Music/paper");
     music.Play();
     player.Image.Position = new Vector2(320, 240);
 }
Exemple #25
0
        //counts and returns how many pills in the list intersect with the given position
        //also removes all the pills that intersect with the given position and plays the nom sound if pills are eaten
        public int countIntersections(Rectangle position, SoundEffect nom)
        {
            int intersections = 0;

            for (int i = 0; i < list.Count; i++)
                {
                if (position.Intersects(list[i].getPosition()))
                    {
                    intersections++;
                    list.RemoveAt(i);
                    nom.Play();
                    }
                }

            return intersections;
        }
Exemple #26
0
 private void onPlay(object sender, RoutedEventArgs e)
 {
     Button playButton = e.OriginalSource as Button;
     if (playButton != null)
     {
         MemoryStream ms = new MemoryStream();
         string fileName = playButton.Tag.ToString();
         // 从独立存储区中读取文件
         try
         {
             using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
             {
                 // 如果文件不存在,跳出
                 if (!iso.FileExists("Radio\\"+fileName)) 
                 {
                     return;
                 }
                 // 打开文件流
                 using (IsolatedStorageFileStream stream = iso.OpenFile("Radio\\" +fileName, FileMode.Open, FileAccess.Read))
                 {
                     byte[] buffer = new byte[2048];
                     int n = 0;
                     // 读入到内存流
                     while ((n = stream.Read(buffer, 0, buffer.Length)) > 0)
                     {
                         ms.Write(buffer, 0, n);
                     }
                 }
             }
         }
         catch
         {
             // 如果未能正确读取文件,就不往下执行
             return;
         }
         // 如果文件长度为0,就不用播放了
         if (ms.Length == 0L)
         {
             ms.Dispose();
             return;
         }
         // 播放声音
         SoundEffect mySound = new SoundEffect(ms.ToArray(), Microphone.Default.SampleRate, AudioChannels.Mono);
         mySound.Play();
         ms.Dispose();
     }
 }
 public BotExplosion(int damage, int radius, float speed, Vector3 pos, ContentManager content)
 {
     this.damage = 0;
     this.radius = radius;
     this.speed = speed;
     position = pos;
     size = 0.15f;
     model = content.Load<Model>(@"models/sphere");
     texture = content.Load<Texture2D>(@"textures/explosiontexture");
     radiusSound = content.Load<SoundEffect>(@"audio/sfx/misslewhoosh");
     impactSound = content.Load<SoundEffect>(@"audio/sfx/MissleExplosion");
     impactSound.Play(0.1f, 1, 0);
     radiusSound.Play(0.5f, 1, 0);
     sphere = new BoundingSphere(position, 0.125f);
     hitPlayerOnce = false;
     timer = 0;
     lifetimer = 500;
 }
        public static void VibrationSound()
        {
            //consider writing the bit that makes the text flash
            Microsoft.Xna.Framework.Audio.SoundEffect sound = SoundEffect.FromStream(TitleContainer.OpenStream("Assets/sound.wav"));

            AppSettings settings = new AppSettings();

            if (settings.ToggleSwitchVibration)
            {
                Microsoft.Devices.VibrateController testVibrateController = Microsoft.Devices.VibrateController.Default;
                testVibrateController.Start(TimeSpan.FromSeconds(3));
            }
            if (settings.ToggleSwitchSound)
            {
                FrameworkDispatcher.Update();
                sound.Play();
            }
        }
Exemple #29
0
        public ExplosionView(Viewport port, Vector2 startPosition, SoundEffect blast)
        {
            this.size = 0.08f;
            this.spawnTime = 0.1f;
            blast.Play();
            camera = new Camera(port);
            this.startPosition = camera.getClickModelCoords(startPosition);

            splitterParticles = new Splitter[MAX_SPLITTER_PARTICLES];

            for (int i = 0; i < MAX_SPLITTER_PARTICLES; i++)
            {
                splitterParticles[i] = new Splitter(i, camera, size, this.startPosition);
                splitterParticles[i].spawn();
            }

            explosion = new Explosion(camera, size, this.startPosition, NUM_OF_FRAMES);
        }
        /// <summary>
        /// Creates a new explosion
        /// </summary>
        /// <param name="position">The position of the explosion within the game world</param>
        /// <param name="content">A ContentManager to load resources with</param>
        public Explosion(uint id, Vector2 position, ContentManager content)
            : base(id)
        {
            this.position = position;

            this.spriteSheet = content.Load<Texture2D>("Spritesheets/tyrian.shp.01D8A7");
            explosionSound = content.Load<SoundEffect>("SFX/Blast");
            explosionSound.Play();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    spriteBounds[i, j] = new Rectangle((120 - j * 12), (126 + i * 14), 12, 14);
                }
            }

            this.explosionState = ExplosionState.Stage1;
            this.explosionTimer = 0;
        }
Exemple #31
0
        private void MainPage_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            String file = "sounds/down.wav";
            while (TouchPanel.IsGestureAvailable)
            {
                GestureSample gesture = TouchPanel.ReadGesture();

                if (gesture.GestureType == GestureType.Tap)
                {
                    //Do something
                    stream = TitleContainer.OpenStream(file);
                    effect = SoundEffect.FromStream(stream);
                    FrameworkDispatcher.Update();
                    _shakeDetect_ShakeEvent(sender, e);
                    effect.Play();

                }
            }
        }