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

Author Topic: Is there a problem with sf::Music::pause ?  (Read 4300 times)

0 Members and 1 Guest are viewing this topic.

dwarfman78

  • Full Member
  • ***
  • Posts: 228
  • I'm bietzsche, Nietzsche !
    • MSN Messenger - cd4c@hotmail.com
    • View Profile
    • Email
Is there a problem with sf::Music::pause ?
« on: May 10, 2014, 09:01:47 pm »
Hi,
am i misreading something in the documentation or there is a problem here ? (found nothing in the forum with getStatus keyword nor in the github bugtracker).


#include <iostream>
#include <SFML/Audio.hpp>

int main()
{
    sf::Music music;
    if (!music.openFromFile("music.ogg"))
        return -1; // error

    music.play();

    music.pause();

    std::cout << music.getStatus();
    if(music.getStatus()!= sf::Music::Paused)
    {
        std::cout << "Problem ?" << std::endl;
    }
    else
    {
        std::cout << "OK" << std::endl;
    }

return 0;
// or loop ..
}

Output :

2Problem ?

Using mingw 4.7, linking statically to SFML.

Thank you for the help.
@dwarfman78
github.com/dwarfman78

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Is there a problem with sf::Music::pause ?
« Reply #1 on: May 10, 2014, 10:35:39 pm »
Looks like a bug indeed. Have you tried with sf::Sound? Which version of SFML?
Laurent Gomila - SFML developer

dwarfman78

  • Full Member
  • ***
  • Posts: 228
  • I'm bietzsche, Nietzsche !
    • MSN Messenger - cd4c@hotmail.com
    • View Profile
    • Email
Re: Is there a problem with sf::Music::pause ?
« Reply #2 on: May 11, 2014, 07:28:13 am »
Have you tried with sf::Sound?

#include <iostream>
#include <SFML/Audio.hpp>

int main()
{
    sf::SoundBuffer buffer;
    if (!buffer.loadFromFile("music.ogg"))
        return -1;

    sf::Sound sound;

    sound.setBuffer(buffer);

    sound.play();

    sound.pause();
    std::cout << sound.getStatus();
    if(sound.getStatus()!= sf::Sound::Paused)
    {
        std::cout << "Problem ?" << std::endl;
    }
    else
    {
        std::cout << "OK" << std::endl;
    }

    return 0;
}

Output :

1OK

I'm using SFML-2.1 release (not any snapshot from github)
@dwarfman78
github.com/dwarfman78

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Is there a problem with sf::Music::pause ?
« Reply #3 on: May 11, 2014, 09:47:00 am »
Can you try the latest development version? There's also a bugfix/soundstream branch that you might try, I don't know if it has been merged into master yet.
Laurent Gomila - SFML developer

dwarfman78

  • Full Member
  • ***
  • Posts: 228
  • I'm bietzsche, Nietzsche !
    • MSN Messenger - cd4c@hotmail.com
    • View Profile
    • Email
Re: Is there a problem with sf::Music::pause ?
« Reply #4 on: May 28, 2014, 09:24:27 pm »
Tested with master branch, same result.

I'm using "stop" instead as a workaround, the behavior is not quite the same obviously but it is ok.
« Last Edit: May 28, 2014, 09:26:02 pm by dwarfman78 »
@dwarfman78
github.com/dwarfman78

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Is there a problem with sf::Music::pause ?
« Reply #5 on: May 28, 2014, 11:06:01 pm »
Quote
Tested with master branch, same result.
The bugfix/soundstream branch has not been merged yet, actually.
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Is there a problem with sf::Music::pause ?
« Reply #6 on: May 29, 2014, 05:38:16 pm »
This should be fixed in the commit I just amended at https://github.com/SFML/SFML/tree/bugfix/soundstream.

The problem was that alSourcePause was being called before alSourcePlay was called because the thread takes time to start up. I made up for this already when fixing the other issues by introducing a thread start state. It now checks to see if it was already paused before alSourcePlay is called and pauses the thread instantly if that is the case. getStatus() also had to be modified to return the true start state as opposed to only Playing.

You can try building this branch (not yet merged into master) and see if it fixes the problem for you.

On a side note: I mentioned here that there are some discrepancies between what the documentation says and what the code really does. It would be nice if you could clarify this Laurent.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

dwarfman78

  • Full Member
  • ***
  • Posts: 228
  • I'm bietzsche, Nietzsche !
    • MSN Messenger - cd4c@hotmail.com
    • View Profile
    • Email
Re: Is there a problem with sf::Music::pause ?
« Reply #7 on: June 02, 2014, 11:37:20 am »
I think the minimal source code provided might have mislead you. Indeed, in the original context, pause is not called immediately after play, given your explanation of the problem I don't think it is solved. I might give the branch a try however.
@dwarfman78
github.com/dwarfman78