Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - DrenikowB

Pages: [1]
1
Audio / Event lag when music is playing
« on: October 12, 2012, 02:10:43 am »
Hello,

I am having an issue with my SFML. I am new to programming with SFML and the issue I have is that when I run my loop for playing music I want to be able to pause the music. It works but it takes multiple attempts of pressing the key before it takes in the event and actually pauses the music. Does anyone know how to fix it? Thanks :D

Here's some code for what I'm trying to do.

        sf::Sound Sound(Buffer);
        while (App.IsOpened()){

                if(first ==true){
                        Sound.Play();
                        first =false;
                }
               
                // Loop while the sound is playing
                if (Sound.GetStatus() == sf::Sound::Playing)
                {
                        // Display the playing position
                        std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec";

                        // Leave some CPU time for other threads
                        sf::Sleep(0.1f);

                        while (App.GetEvent(Event))
               {
                                // Close window : exit
                                App.GetEvent(Event);
                                if (Event.Type == sf::Event::Closed){
                                        App.Close();
                                        Sound.Stop();
                                }

                                // Escape key : exit
                                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)){
                                        App.Close();
                                        Sound.Stop();
                                }
                                if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key:: P)){
                                        Sound.Pause();
                                }

                                const sf::Input &input = App.GetInput();

                        }

                        App.Display();
                }

Pages: [1]
anything