Play() public method

Start or resume playing the audio stream. 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 stream is played.
public Play ( ) : void
return void
 void SfmlPlay(SFMLMusic audio)
 {
     audio.Stop();
     audio.Volume = m_Volume;
     audio.Play();
     m_CurrentMusic = audio;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Play a music
        /// </summary>
        private static void PlayMusic()
        {
            // Load an ogg music file
            Music Music = new Music("datas/sound/lepidoptera.ogg");

            // Display music informations
            Console.WriteLine("lepidoptera.ogg :");
            Console.WriteLine(" " + Music.Duration      + " sec");
            Console.WriteLine(" " + Music.SampleRate    + " samples / sec");
            Console.WriteLine(" " + Music.ChannelsCount + " channels");

            // Play it
            Music.Play();

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

                // Leave some CPU time for other processes
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 3
0
        public static void Play(Musics Index, bool Loop = false)
        {
            string Directory = Directories.Musics.FullName + (byte)Index + Format;

            // Apenas se necessário
            if (Device != null)
            {
                return;
            }
            if (!Lists.Options.Musics)
            {
                return;
            }
            if (!File.Exists(Directory))
            {
                return;
            }

            // Carrega o áudio
            Device        = new SFML.Audio.Music(Directory);
            Device.Loop   = true;
            Device.Volume = 20;
            Device.Loop   = Loop;

            // Reproduz
            Device.Play();
            Current = (byte)Index;
        }
Ejemplo n.º 4
0
        static void Main()
        {
            var cult = new Cult("Inversetroids") {ClearColor = Colors.Black};

            Fonts.Init();

            InitGame(cult);
            InitUI(cult);
            InitMainMenu(cult);
            InitGameOver(cult);

            cult.Undrawn = new World(cult);

            var music = new Music("rsc/music/Beat1.wav");
            music.Play();

            new Ticker(cult.Undrawn, music.Duration, delegate { music.Stop(); music.Play(); });

            cult.CurrentWorld = Menu;
            cult.Run();
        }
Ejemplo n.º 5
0
        public static void PlayMusic(string name)
        {
            var state = 0;
            var tween = Tween.Create(TweenType.OutQuad, 0, GameOptions.MusicVolume, 0.5f, () => state = 1);
            var music = new Music(Path.Combine(GameOptions.MusicLocation, name));
            var watch = new Stopwatch();

            currentMusic = music;

            music.Volume = 0;
            music.Play();

            watch.Start();

            Timer.EveryFrame(() =>
            {
                double dt = watch.Elapsed.TotalSeconds;
                watch.Restart();

                if (music != currentMusic && state != 3)
                    state = 2;

                switch (state)
                {
                    case 0: // fade in
                        music.Volume = (float)tween(dt);
                        break;
                    case 1: // normal play
                        if (music.PlayingOffset.TotalSeconds >= music.Duration.TotalSeconds - 1)
                            state = 2;
                        break;
                    case 2: // setup fadeout
                        tween = Tween.Create(TweenType.OutQuad, music.Volume, 0, 0.5f, () => state = 10);
                        state = 3;
                        break;
                    case 3: // fade out
                        music.Volume = (float)tween(dt);

                        if (state != 3)
                            return true;

                        break;
                }

                return false;
            });
        }
Ejemplo n.º 6
0
        public static void Play(Musics Index, bool Loop = false)
        {
            System.IO.FileInfo File = new System.IO.FileInfo(Directories.Musics.FullName + (byte)Index + Format);

            // Apenas se necessário
            if (Device != null) return;
            if (Editor_Maps.Objects.Visible && !Editor_Maps.Objects.butAudio.Checked) return;
            if (!File.Exists) return;

            // Carrega o áudio
            Device = new SFML.Audio.Music(Directories.Musics.FullName + (byte)Index + Format);
            Device.Loop = true;
            Device.Volume = 20;
            Device.Loop = Loop;

            // Reproduz
            Device.Play();
            Current = (byte)Index;
        }
Ejemplo n.º 7
0
        public GameWorld()
        {
            mEntities = new List<Entity>();
            mEnemies  = new List<Enemy>();
            mPhysics  = new World(new Vector2(0f, 0.0981f));
            mWin      = true;

            mTimeText.Position  = new Vector2f(580f, 670f);
            mStartInfo.Position = new Vector2f(500f, 300f);
            mWinText.Position   = new Vector2f(400f, 200f);
            mLoseText.Position  = new Vector2f(400f, 200f);
            //mStartInfo.Color    = new Color(255, 0, 0);

            ConvertUnits.SetDisplayUnitToSimUnitRatio(8f);
            Delta.create();
            mCountdown.Start();
            mGameState = GameState.START;

            mMusic        = new Music("resources/sound/theme.wav");
            mMusic.Loop   = true;
            mMusic.Volume = 40f;
            mMusic.Play();
        }
Ejemplo n.º 8
0
 void PlayMusic(String filename)
 {
     Music = new Music(filename);
     Music.Play();
 }
Ejemplo n.º 9
0
        public static void Main()
        {
            /*
            RenderWindow window = new RenderWindow(new VideoMode(200, 200), "SFML works!");

            Console.WriteLine("test");
            Console.ReadKey();
            */

            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");
            window.Closed += new EventHandler(OnClose);

            // Load a sprite to display
            Texture texture = new Texture("media/image/mario.png");
            Sprite sprite = new Sprite(texture);

            // Create a graphical text to display
            Font font = new Font("media/font/arial.ttf");
            Text text = new Text("Hello SFML", font, 50);

            // Load & play music
            Music music = new Music("media/sound/mario.ogg");
            music.Play();

            // starts the Stopwatch
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            // last mouse position
            Vector2i last_mouse_position = new Vector2i(0, 0);

            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                float speed = 0.1f * Convert.ToSingle(stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Reset();
                stopwatch.Start();

                if (Keyboard.IsKeyPressed(Keyboard.Key.Up))
                {
                    sprite.Position = new Vector2f(sprite.Position.X, sprite.Position.Y - speed);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Down))
                {
                    sprite.Position = new Vector2f(sprite.Position.X, sprite.Position.Y + speed);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Left))
                {
                    sprite.Position = new Vector2f(sprite.Position.X - speed, sprite.Position.Y);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
                {
                    sprite.Position = new Vector2f(sprite.Position.X + speed, sprite.Position.Y);
                }

                // only if its a new mouse position
                if (!last_mouse_position.Equals(Mouse.GetPosition()))
                {
                    if (Mouse.IsButtonPressed(Mouse.Button.Left))
                    {
                        Console.WriteLine("Klick Maustaste: Links; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                    if (Mouse.IsButtonPressed(Mouse.Button.Middle))
                    {
                        Console.WriteLine("Klick Maustaste: Mitte; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                    if (Mouse.IsButtonPressed(Mouse.Button.Right))
                    {
                        Console.WriteLine("Klick Maustaste: Rechts; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                }

                // Clear screen
                window.Clear();

                // Draw the sprite
                window.Draw(sprite);

                // Draw the string
                window.Draw(text);

                // Update the window
                window.Display();
            }
        }
Ejemplo n.º 10
0
        public Game()
        {
            Started = false;
            Running = false;

            // Setup Window
            Bounds = new FloatRect(0, 0, ResolutionDefault.X, ResolutionDefault.Y);
            WindowSettings = new ContextSettings();
            WindowSettings.AntialiasingLevel = 6;
            CreateWindow();

            // Black Bars (for fullscreen)
            Layer_BlackBars = new Layer();
            RectangleShape BlackBarLeft = new RectangleShape(new Vector2f(2000, 5000));
            BlackBarLeft.Position = new Vector2f(-BlackBarLeft.Size.X, 0);
            BlackBarLeft.FillColor = new Color(0, 0, 0);
            Layer_BlackBars.AddChild(BlackBarLeft);
            RectangleShape BlackBarRight = new RectangleShape(new Vector2f(2000, 5000));
            BlackBarRight.Position = new Vector2f(Size.X, 0);
            BlackBarRight.FillColor = new Color(0, 0, 0);
            Layer_BlackBars.AddChild(BlackBarRight);

            // Setup
            Layer_Background = new Layer();
            Layer_Other = new Layer();
            Layer_Objects = new Layer();
            Layer_OtherAbove = new Layer();
            Layer_GUI = new Layer();

            // Start Menu
            StartMenu = new StartMenu(this);
            Layer_GUI.AddChild(StartMenu);

            Music = new Music("assets/audio/music/Speed Pirate - LuigiSounds.ogg");
            Music.Loop = true;
            Music.Play();

            // Game Loop
            Stopwatch clock = new Stopwatch();
            clock.Start();
            while (Window.IsOpen())
            {
                // Process events
                Window.DispatchEvents();

                if (clock.Elapsed.TotalSeconds >= (1.0f / FPS))
                {
                    if (CloseNextUpdate)
                    {
                        Window.Close();
                        return;
                    }

                    // Clear screen
                    Window.Clear();

                    // Update Game
                    Update((float)clock.Elapsed.TotalSeconds);
                    clock.Restart();

                    // Draw Game
                    Draw();

                    // Update the window
                    Window.Display();
                }
            }
        }
Ejemplo n.º 11
0
 public void Start()
 {
     //Load Assets and Set Variables
     lose = false;
     m = new Music("Content/mixdown.ogg");
     m.Loop = true;
     m.Play();
     F = new Font("Content/Animated.ttf");
     BG = new Sprite(new Texture(new Image("Content/BG.png")), new IntRect(0, 0, W, H));
     pointSprite = new Sprite(new Texture(new Image("Content/Point.png")), new IntRect(0,0,16,16));
     window.MouseMoved += MouseInput;
     window.KeyPressed += KeyboardInput;
     window.KeyReleased += KeyboardReleaseInput;
     Player.Load();
     while(window.IsOpen())
     {
         window.DispatchEvents();
         window.Clear(new Color(0,0,0));
         Draw();
         window.Display();
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Plays a music track by the given <see cref="MusicID"/>.
        /// </summary>
        /// <param name="id">The ID of the music to play.</param>
        /// <returns>
        /// True if the music played successfully; otherwise false.
        /// </returns>
        public bool Play(MusicID id)
        {
            try
            {
                // If the music is already playing, continue to play it
                if (_playingInfo != null && _playingInfo.ID == id)
                {
                    if (_playing.Status != SoundStatus.Playing)
                        _playing.Play();

                    return true;
                }

                // Stop the old music
                Stop();

                // Get the info for the music to play
                var info = GetMusicInfo(id);
                if (info == null)
                    return false;

                // Start the new music
                _playingInfo = info;

                var file = GetFilePath(info);
                try
                {
                    _playing = new Music(file);
                }
                catch (LoadingFailedException ex)
                {
                    const string errmsg = "Failed to load music `{0}`: {1}";
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, info, ex);
                    Debug.Fail(string.Format(errmsg, info, ex));

                    _playing = null;
                    _playingInfo = null;

                    return false;
                }

                // Set the values for the music and start playing it
                _playing.Volume = Volume;
                _playing.Loop = Loop;
                _playing.RelativeToListener = true;
                _playing.Play();
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to play music with ID `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, id, ex);
                Debug.Fail(string.Format(errmsg, id, ex));
            }

            return true;
        }
Ejemplo n.º 13
0
 public static void PlayMusic(string filename)
 {
     var music = new Music(filename);
     music.Play();
 }
 void Play(SFMLMusic audio)
 {
     audio.Stop();
     audio.Volume = m_Volume;
     audio.Play();
 }
Ejemplo n.º 15
0
        public StandardMelee(InputHandler handler)
        {
            _mousePosition = new Vector2f(500, 500);

            CurrentStatus = StatusState.WaitingForPlayers;

            uiState = UIStateTypes.Normal;
            currentHotkey = null;
            currentHotkeySheet = null;
            standardHotkeys = Settings.GetSheet("standard_game_mode_controls");

            InputHandler = handler;
            myId = 0;
            map = new TileMap();

            allowMinimapCameraMove = true;
            selectedUnits = null;
            controlGroups = new Dictionary<Keyboard.Key, List<EntityBase>>();

            for (int i = 27; i <= 35; i++)
            {
                controlGroups.Add((Keyboard.Key) i, new List<EntityBase>());
            }

            controlBoxP1 = new Vector2f(0, 0);
            controlBoxP2 = new Vector2f(0, 0);
            selectedAttackMove = false;
            releaseSelect = false;

            CameraPosition = new Vector2f(0, 0);

            miniMap = new MiniMap(map, Fog, entities);

            //Load Sprites
            bottomHUDGUI = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/BottomGUI.png"));
            alertHUDAlert = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_Alert.png"));
            alertHUDUnitCreated = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_UnitCreated.png"));
            alertHUDBuildingCreated =
                new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/Alert_BuildingFinished.png"));

            avatarWorker = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_AVATAR_WORKER.png"));

            hudBoxUnit = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Unit.png"));
            hudBoxBuilding = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/HUD_BOX_Building.png"));

            hudControlBox = new Sprite(ExternalResources.GTexture("Resources/Sprites/HUD/ControlGroupBox.png"));
            hudControlBox.Origin = new Vector2f(hudControlBox.TextureRect.Width/2, 0);

            viewBounds = new Sprite(ExternalResources.GTexture("Resources/Sprites/Hud/ViewBounds.png"));

            //Load Sounds
            moveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/MoveCommand/0.wav"));
            attackMoveSound = new Sound(ExternalResources.GSoundBuffer("Resources/Audio/AttackCommand/0.wav"));

            backgroundMusic = new Music("Resources/Audio/Music/In Game/mario.wav");
            backgroundMusic.Loop = true;
            backgroundMusic.Volume = Settings.MUSICVOLUME;
            backgroundMusic.Play();
        }
Ejemplo n.º 16
0
 public void PlayMusic(string musicName)
 {
     _currentMusic = _music[musicName];
     _currentMusic.Play();
 }
 void Resume(SFMLMusic audio)
 {
     audio.Play();
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Play the music.
 /// </summary>
 public void Play()
 {
     music.Volume = Util.Clamp(GlobalVolume * Volume, 0f, 1f) * 100f;
     music.Play();
 }
Ejemplo n.º 19
0
        public static void InitializeMusic()
        {
            if (!Music) return;
            string rndmusic = GetRandomMusic ();
            if (rndmusic == null) return;

            CurrentMusic = new Music(rndmusic) {Loop = true};
            CurrentMusic.Play ();
        }