1
Audio / Trouble with sf::Music
« on: August 27, 2015, 01:12:34 pm »
Hello, i write simple game with SFML.
I using sf::Sound and all is ok. If i use sf::Music periodically i get error in console:
My code:
Please, tell me where my mistake. And sorry for my bad english.
I using sf::Sound and all is ok. If i use sf::Music periodically i get error in console:
(click to show/hide)
...
An internal OpenAL call failed in SoundSource.cpp(177).
Expression:
alGetSourcei(m_source, AL_SOURCE_STATE, &status)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundStream.cpp(312).
Expression:
alSourcePlay(m_source)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundStream.cpp(324).
Expression:
alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundSource.cpp(177).
Expression:
alGetSourcei(m_source, AL_SOURCE_STATE, &status)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundSource.cpp(177).
Expression:
alGetSourcei(m_source, AL_SOURCE_STATE, &status)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
...
An internal OpenAL call failed in SoundSource.cpp(177).
Expression:
alGetSourcei(m_source, AL_SOURCE_STATE, &status)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundStream.cpp(312).
Expression:
alSourcePlay(m_source)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundStream.cpp(324).
Expression:
alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &nbProcessed)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundSource.cpp(177).
Expression:
alGetSourcei(m_source, AL_SOURCE_STATE, &status)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
An internal OpenAL call failed in SoundSource.cpp(177).
Expression:
alGetSourcei(m_source, AL_SOURCE_STATE, &status)
Error description:
AL_INVALID_OPERATION
The specified operation is not allowed in the current state.
...
My code:
(click to show/hide)
musicFiles - array of strings filename
curMusicFile - iterator to array
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:{
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();
}
}
}
}
MusicPlayer mp;
mp.addMusic("file.wab");
Clock gameTime;
while (mainWindow.isOpen())
{
mp.doPlay(gameTime.getElapsedTime());
doLogic(gameTime.restart().asMicroseconds() / 800.0f);
...
}
mp.addMusic("file.wab");
Clock gameTime;
while (mainWindow.isOpen())
{
mp.doPlay(gameTime.getElapsedTime());
doLogic(gameTime.restart().asMicroseconds() / 800.0f);
...
}
Please, tell me where my mistake. And sorry for my bad english.