SFML community forums

Help => Audio => Topic started by: wmbuRn on January 28, 2014, 12:00:23 am

Title: Cant get to play next song after first is finnished
Post by: wmbuRn on January 28, 2014, 12:00:23 am
I tried something simple. It should work, but simply it doesnt and i have no idea why.

sf::Music musicPlayer;
    musicPlayer.openFromFile("song1.wav");
    musicPlayer.play();

    if ( musicPlayer.getStatus() == sf::Music::Stopped )
// OR if ( musicPlayer.getStatus() != sf::Music::Playing )
    {
    musicPlayer.openFromFile("song2.wav");
    musicPlayer.play();
    std::cout << "Playing second song" << std::endl;
    }
 

So after first song is finished it should play 2nd song, but it doesnt, no matter what conditional i use.
Anyone have idea how to implement this?

Thanks in advance
-----------------------------------------------------------------------------------
Also i have popping/cracking sound when i use .ogg files. .wav files works ok.
I have sfml 2.1.
Title: Re: Cant get to play next song after first is finnished
Post by: G. on January 28, 2014, 12:19:28 am
play() is not blocking
When your program reaches your condition the first song is still playing.
Title: Re: Cant get to play next song after first is finnished
Post by: wmbuRn on January 28, 2014, 12:24:13 am
yeah. Moved conditional after

 while (app.isOpen())
    {

     if ( musicPlayer.getStatus() == sf::Music::Stopped )
          {
           musicPlayer.openFromFile("song2.wav");
           musicPlayer.play();
           std::cout << "Playing second intro" << std::endl;
          }

        sf::Event event;
        ....
 

And its working. Thank you G.