Skip to content

Commit

Permalink
Add Extra Music Control
Browse files Browse the repository at this point in the history
added extra controls for music to allow pausing and resuming the
(current) music instead of only playing and stopping.
also added ability to get the position (in sf::Time) of the current
music. if the current music is stopped, the time returned is zero. note
that no checks are made to make sure that the music actually exists, as
with getCurrentMusicStatus.
  • Loading branch information
Hapaxia committed May 1, 2018
1 parent 2a46b30 commit d035efa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions SfmlSoundSystem/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ bool Control::assignVolumeMusic(const std::string& musicId, const float volume)
return true;
}

sf::Time Control::getCurrentMusicPosition() const
{
if (getCurrentMusicStatus() != sf::SoundSource::Status::Stopped)
return m_musics[m_currentMusicVoice].getPlayingOffset();

return sf::Time::Zero;
}

void Control::pauseMusic()
{
if (getCurrentMusicStatus() == sf::SoundSource::Status::Playing)
m_musics[m_currentMusicVoice].pause();
}

void Control::resumeMusic()
{
if (getCurrentMusicStatus() == sf::SoundSource::Status::Paused)
m_musics[m_currentMusicVoice].play();
}

void Control::stopFx()
{
for (auto& voice : m_voices)
Expand Down
5 changes: 4 additions & 1 deletion SfmlSoundSystem/Control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
namespace sfmlSoundSystem
{

// SSS (SFML Sound System) v1.2 - Control
// SSS (SFML Sound System) v1.3 - Control
class Control
{
public:
Expand All @@ -66,6 +66,9 @@ class Control
bool playMusic(const std::string& musicId, sf::Time transitionDuration = sf::Time::Zero, float volumeMultiplier = 1.f);
bool assignVolumeSound(const std::string& soundId, float volume = 1.f);
bool assignVolumeMusic(const std::string& musicId, float volume = 1.f);
sf::Time getCurrentMusicPosition() const;
void pauseMusic();
void resumeMusic();
void stopFx();
void stopMusic();
void stopAll();
Expand Down

0 comments on commit d035efa

Please sign in to comment.