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

Author Topic: Cant get to play next song after first is finnished  (Read 2717 times)

0 Members and 1 Guest are viewing this topic.

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Cant get to play next song after first is finnished
« 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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Cant get to play next song after first is finnished
« Reply #1 on: January 28, 2014, 12:19:28 am »
play() is not blocking
When your program reaches your condition the first song is still playing.

wmbuRn

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • Email
Re: Cant get to play next song after first is finnished
« Reply #2 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.

 

anything