SFML community forums

Help => Audio => Topic started by: fatum on September 16, 2011, 09:32:30 pm

Title: Music only plays if directly preceded by a loop? (SFML2)
Post by: fatum on September 16, 2011, 09:32:30 pm
I have this bit here:

Code: [Select]

sf::Music test;

if (!test.OpenFromFile("test.ogg"))
{
std::cout << "Oh No!" << std::endl;
}
elsae
{
test.Play();
}


Which doesn't play the audio!  However, if I append this right after "test.Play();"

Code: [Select]

for (;;);


The Music plays as expected.  I've also tried adding test.Play(); in the ::update(); method that's called every frame.

What could the issue be?  Thanks for any help!
Title: Music only plays if directly preceded by a loop? (SFML2)
Post by: Laurent on September 16, 2011, 09:46:23 pm
What is there after this code? If the Music instance is local to the function, it's destroyed immediately and thus is stopped. It must be alive as long as you want to play it.