Hi Folks,
So I am using sf::Sound for the first time and I am having a bit of trouble where sounds seem to stop playing before the entire wav file has finished playing.
What I have is:
- A std::vector of sf::Sound in my private section of my class.
vector<sf::Sound> soundVtr;
- When I play a sound I simply push_back a new sf::Sound to this std::vector
soundVtr.push_back(sf::Sound(*passed_SoundBuffer));
- During each game tick/loop, I call the below removeStoppedSounds() which goes through the std::vector of the sf::Sounds to check the status. If the status is sf::SoundSource::Stopped
However as stated, when I call the removeStoppedSounds() during the gameloop, I find that sounds don't finish, i.e. a 2 second wav file gets stopped withing a few milliseconds.
If I comment out the call to removeStoppedSounds() then it plays until the end. So I am assuming this method is something removing the sf::Sound before it can be played until the end of the wav file.
So is this something to do with using std::vector? If yes, then how I can store sf::sounds so that they can be played until the end of the wav file?
Or something to do with sf::Sound::getStatus()?
bool soundsList::isSoundPlaying(sf::Sound *passed_Sound)
{
if (passed_Sound->getStatus() == sf::SoundSource::Stopped)
{
//cout << "stopped playing\n";
return false;
}
else
{
cout << "still playing\n";
return true;
}
}
void soundsList::removeStoppedSounds()
{
for (int i = 0; i < soundVtr.size(); i++)
{
if (!isSoundPlaying(&soundVtr[i]))
{
soundVtr.erase(soundVtr.begin() + i);
cout << "erased sound at index " << i << "\n";
//i--;
}
}
}