musicFiles - array of strings filename
curMusicFile - iterator to array
void MusicPlayer::playNext()
{
if (!musicPlayer->openFromFile(*(curMusicFile++)))
throw runtime_error("GameSpace::MusicPlayer::doPlay openFromFile error");
musicPlayer->play();
curLength = musicPlayer->getPlayingOffset();
}
//////////////////////////////////////////////////////////////////////////
void MusicPlayer::doPlay(const sf::Time& delta)
{
if (!musicFiles.empty())
{
if (!musicPlayer)
{
curMusicFile = musicFiles.begin();
musicPlayer = unique_ptr<Music>(new Music());
playNext();
}
else
{
curLength += delta;
if (curLength >= musicPlayer->getDuration())
{
if (curMusicFile == musicFiles.end())
curMusicFile = musicFiles.begin();
musicPlayer->stop();
playNext();
}
}
}
}
in main:
MusicPlayer mp;
mp.addMusic("file.wab");
Clock gameTime;
while (mainWindow.isOpen())
{
mp.doPlay(gameTime.getElapsedTime());
doLogic(gameTime.restart().asMicroseconds() / 800.0f);
...
}