Play() public method

Start or resume playing the sound. This function starts the stream if it was stopped, resumes it if it was paused, and restarts it from beginning if it was it already playing. This function uses its own thread so that it doesn't block the rest of the program while the sound is played.
public Play ( ) : void
return void
        public static void PlaySound(string filename)
        {
            var buffer = new SoundBuffer(filename);

            var sound = new Sound(buffer);
            sound.Play();
        }
Beispiel #2
0
        /// <summary>
        /// Play a sound
        /// </summary>
        private static void PlaySound()
        {
            // Load a sound buffer from a wav file
            SoundBuffer Buffer = new SoundBuffer("datas/sound/footsteps.wav");

            // Display sound informations
            Console.WriteLine("footsteps.wav :");
            Console.WriteLine(" " + Buffer.Duration      + " sec");
            Console.WriteLine(" " + Buffer.SampleRate    + " samples / sec");
            Console.WriteLine(" " + Buffer.ChannelsCount + " channels");

            // Create a sound instance and play it
            Sound Sound = new Sound(Buffer);
            Sound.Play();

            // Loop while the sound is playing
            while (Sound.Status == SoundStatus.Playing)
            {
                // Display the playing position
                Console.CursorLeft = 0;
                Console.Write("Playing... " + Sound.PlayingOffset + " sec     ");

                // Leave some CPU time for other processes
                Thread.Sleep(100);
            }
        }
Beispiel #3
0
        public void PlaySound(string name, bool loop = false, int volume = 100)
        {
            for (var i = 0; i < _sounds.Count; i++)
            {
                if (_sounds[i].Sound.Status == SoundStatus.Stopped)
                {
                    _sounds[i].Dispose();
                    _sounds.RemoveAt(i);
                    i--;
                }
            }

            if (name.Contains("background") && _sounds.Any(t => t.Name == name))
            {
                if (_sounds.Single(t => t.Name == name).Sound.Status != SoundStatus.Playing)
                {
                    _sounds.Single(t => t.Name == name).Sound.Play();
                }
            }
            else
            {
                var sound = new Sound(ResourceManager.Instance[name] as SoundBuffer);
                _sounds.Add(new SoundData(name, sound));
                sound.Loop = loop;
                sound.Volume = volume;
                sound.Play();
            }
        }
        public void PlaySound(string soundName)
        {
            var sound = new Sound(_sounds[soundName])
            {
                Loop = true
            };

            sound.Play();
        }
Beispiel #5
0
 public void PlaySound(string name)
 {
     Sound sound = new Sound();
     if (m_SoundBufferList.ContainsKey(name))
     {
         sound.SoundBuffer = m_SoundBufferList[name];
         sound.Play();
     }
 }
Beispiel #6
0
 /// <summary>
 /// Plays this <see cref="IAudioStreamImp" />.
 /// </summary>
 /// <param name="loop"><c>true</c> if this <see cref="IAudioStreamImp" /> shall be looped; otherwise, <c>false</c>.</param>
 public void Play(bool loop)
 {
     if (IsStream)
     {
         _outputStream.Loop = loop;
         _outputStream.Play();
     }
     else
     {
         _outputSound.Loop = loop;
         _outputSound.Play();
     }
 }
Beispiel #7
0
        public static void play(Sample sample, float volume = 0.65f, float pan = 0f, float pitch = 1f)
        {
            if (sample == null) return;
            if (Application.audio_disabled) return;

            var sound = new SA.Sound();

            sounds.Add(sound);
            sound.SoundBuffer = sample.buffer;
            sound.Loop = false;
            sound.Pitch = pitch;

            sound.Volume = volume * volume * sample.volume_modifier * 100f;
            sound.Play();
        }
Beispiel #8
0
        /// <summary>
        /// initialize Player and Enemies, by calling the constructors
        /// </summary>
        public static void Initialize()
        {
            gTime = new GameTime();
            BackgroundMusic = new Sound(new SoundBuffer("Sound/asia_1.ogg"));
            BackgroundMusic.Loop = true;
            BackgroundMusic.Volume = 30;
            BackgroundMusic.Play();

            JumpSound = new Sound(new SoundBuffer("Sound/jumpSound.wav"));
            JumpSound.Volume = 100;

            map = new Map(new System.Drawing.Bitmap("Pictures/Map.bmp"));
            Player = new Player(new Vector2f(map.TileSize + 30,map.TileSize + 30));
            enemy1 = new Enemy("Pictures/EnemyGreen.png", new Vector2f(800, 100), "Pictures/EnemyGreenMove.png");
            enemy2 = new Enemy("Pictures/EnemyRed.png", new Vector2f(100, 600), "Pictures/EnemyGreenMove.png");
        }
        public void PlaySound(string soundName, double listenerX, double listenerY, double soundX, double soundY, int maxSoundDistance)
        {
            var distanceX = Math.Abs(listenerX - soundX);
            var distanceY = Math.Abs(listenerY - soundY);
            var totalDistance = Math.Sqrt((Math.Pow(distanceX, 2) + Math.Pow(distanceY, 2)));

            if (totalDistance > maxSoundDistance) return;

            var volume = (int)(maxSoundDistance - totalDistance) * (100 / maxSoundDistance);

            var sound = new Sound(_sounds[soundName])
            {
                Volume = volume
            };
            sound.Play();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            // Test();
            // return;

            Logger.WriteLine(args[0]);

            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
            {
                Logger.WriteLine(eventArgs.ExceptionObject);
            };

            var fileStream = File.Open("C:\\Users\\Admin\\Downloads\\Similar Outskirts - Shockwave.mp3", FileMode.Open);

            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            var sound = new Sound(new BinaryReader(fileStream));

            sound.decodeFullyInto(writer);
            fileStream.Close();

            var wavBytes = ms.ToArray();

            short[] samples = new short[wavBytes.Length / 2];
            Buffer.BlockCopy(wavBytes, 0, samples, 0, wavBytes.Length);

            var sound1 = new SFML.Audio.Sound(new SoundBuffer(samples, 2, 44100));

            sound1.Play();


            //Music sfmlMusic = new Music(wavBytes);
            //sfmlMusic.Play();

            Console.Read();

            Window window = new AudioPlayerWindow(args[0]);

            window.Run();
        }
Beispiel #11
0
        public static Sound Play(string soundName, Vector3f position)
        {
            if (sounds.ContainsKey(soundName))
            {
                var sound = new Sound(sounds[soundName])
                                {
                                    RelativeToListener = false, // Don't follow the listener around.
                                    Position = position,
                                    MinDistance = 400f,
                                    Attenuation = 1f,
                                };

                sound.Play();

                return sound;
            }
            else
            {
                Console.WriteLine("Unable to play sound, file not found: " + soundName);

                return null;
            }
        }
Beispiel #12
0
 /// <summary>
 /// Play the sound.
 /// </summary>
 public void Play()
 {
     sound.Volume = Util.Clamp(GlobalVolume * Volume, 0f, 1f) * 100f;
     sound.Play();
 }
Beispiel #13
0
        /// <summary>
        /// Loads (if needed) a sound and plays it.
        /// </summary>
        public static void PlaySound(string name)
        {
            var sound = new Sound(LoadSound(name));
            sound.Volume = GameOptions.SoundVolume;
            
            sound.Play();
            Sounds.Add(sound);

            Sounds.RemoveAll(snd => snd.Status != SoundStatus.Playing);
        }
        public void LoadContent()
        {
            Level = new Map(new System.Drawing.Bitmap("Assets/Bitmap-Levels/Level3.bmp"));
            Store = new Sprite(new Texture("Assets/Textures/Raster.png"));
            Infobox = new Sprite(new Texture("Assets/Textures/Infotafel.png"));
            Infobox.Position = new Vec2f(0, Game.WindowSize.Y - 192);

            font = new Font("Assets/Fonts/data-latin.ttf");

            txt = new Text("", font, 20);
            txt.Position = new Vec2f(Infobox.Position.X + 10, Infobox.Position.Y + 40);

            MoneyTxt = new Text("", font, 20);
            MoneyTxt.Position = new Vec2f(Infobox.Position.X + 10, Infobox.Position.Y + 10);

            BackgroundMusic = new Sound(new SoundBuffer("Assets/Sounds/Farm-SoundBible.com-1720780826.wav"));
            BackgroundMusic.Loop = true;
            BackgroundMusic.Volume = 100;
            BackgroundMusic.Play();
        }
Beispiel #15
0
        public static void PlaySound(string name)
        {
            Sound s;

            try
            {
                s = new Sound(LoadSound(name)) { Volume = GameOptions.SoundVolume };
                s.Play();
            }
            catch
            {
                return;
            }

            Sounds.Add(s);

            Sounds.RemoveAll(snd => snd.Status != SoundStatus.Playing);
        }
Beispiel #16
0
        public static void PlaySound(string name, Vector2f position)
        {
            const float maxDist = 2000;
            const float maxVol = 25;
            const float pitchVariation = 0.25f;

            Sounds.RemoveAll(snd => snd.Status != SoundStatus.Playing);

            var dist = Util.Distance(Program.Camera.Position, position);
            var volume = Util.Clamp(1 - (dist / maxDist), 0, 1);

            if (volume <= 0)
                return;

            // TODO: limit per sound
            if (Sounds.Count >= 10)
                return;

            int count;
            if (!SoundCounters.TryGetValue(name, out count))
                count = 0;

            if (count > 0)
                return;

            SoundCounters[name] = count + 1;

            var sound = new Sound(LoadSound(name));
            sound.Volume = maxVol * volume;
            sound.Pitch = 1 + ((float)Program.Random.NextDouble() * 2 - 1) * pitchVariation;

            sound.Play();
            Sounds.Add(sound);
        }
Beispiel #17
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            // Check that the device can capture audio
            if (SoundRecorder.IsAvailable == false)
            {
                Console.WriteLine("Sorry, audio capture is not supported by your system");
                return;
            }

            // Choose the sample rate
            Console.WriteLine("Please choose the sample rate for sound capture (44100 is CD quality) : ");
            uint sampleRate = uint.Parse(Console.ReadLine());

            // Wait for user input...
            Console.WriteLine("Press enter to start recording audio");
            Console.ReadLine();

            // Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
            SoundBufferRecorder recorder = new SoundBufferRecorder();

            // Audio capture is done in a separate thread, so we can block the main thread while it is capturing
            recorder.Start(sampleRate);
            Console.WriteLine("Recording... press enter to stop");
            Console.ReadLine();
            recorder.Stop();

            // Get the buffer containing the captured data
            SoundBuffer buffer = recorder.SoundBuffer;

            // Display captured sound informations
            Console.WriteLine("Sound information :");
            Console.WriteLine(" " + buffer.Duration     + " seconds");
            Console.WriteLine(" " + buffer.SampleRate   + " samples / seconds");
            Console.WriteLine(" " + buffer.ChannelCount + " channels");

            // Choose what to do with the recorded sound data
            Console.WriteLine("What do you want to do with captured sound (p = play, s = save) ? ");
            char choice = char.Parse(Console.ReadLine());

            if (choice == 's')
            {
                // Choose the filename
                Console.WriteLine("Choose the file to create : ");
                string filename = Console.ReadLine();

                // Save the buffer
                buffer.SaveToFile(filename);
            }
            else
            {
                // Create a sound instance and play it
                Sound sound = new Sound(buffer);
                sound.Play();

                // Wait until finished
                while (sound.Status == SoundStatus.Playing)
                {
                    // Display the playing position
                    Console.CursorLeft = 0;
                    Console.Write("Playing... " + sound.PlayingOffset + " sec     ");

                    // Leave some CPU time for other threads
                    Thread.Sleep(100);
                }
            }

            // Finished !
            Console.WriteLine("\nDone !");
        }
Beispiel #18
0
 protected virtual void PlaySound(Sound sound)
 {
     //TODO: Set sound properties based on player's camera
     sound.Volume = Settings.SOUNDVOLUME;
     if (sound.Status != SoundStatus.Playing)
         sound.Play();
 }