SFML community forums

Help => Audio => Topic started by: dwarfman78 on May 10, 2014, 09:01:47 pm

Title: Is there a problem with sf::Music::pause ?
Post by: dwarfman78 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.
Title: Re: Is there a problem with sf::Music::pause ?
Post by: Laurent on May 10, 2014, 10:35:39 pm
Looks like a bug indeed. Have you tried with sf::Sound? Which version of SFML?
Title: Re: Is there a problem with sf::Music::pause ?
Post by: dwarfman78 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)
Title: Re: Is there a problem with sf::Music::pause ?
Post by: Laurent 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.
Title: Re: Is there a problem with sf::Music::pause ?
Post by: dwarfman78 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.
Title: Re: Is there a problem with sf::Music::pause ?
Post by: Laurent 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.
Title: Re: Is there a problem with sf::Music::pause ?
Post by: binary1248 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 (https://github.com/SFML/SFML/pull/592#issuecomment-44145942) 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.
Title: Re: Is there a problem with sf::Music::pause ?
Post by: dwarfman78 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.