void SoundNode::changeSoundState(SoundState newSoundState) { if (newSoundState == m_State) { return; } if (m_State == Unloaded) { open(); } if (newSoundState == Unloaded) { close(); } if (getState() == NS_CANRENDER) { long long curTime = Player::get()->getFrameTime(); if (m_State == Unloaded) { startDecoding(); m_StartTime = curTime; m_PauseTime = 0; } if (newSoundState == Paused) { m_PauseStartTime = curTime; AudioEngine::get()->pauseSource(m_AudioID); } else if (newSoundState == Playing && m_State == Paused) { m_PauseTime += curTime-m_PauseStartTime; AudioEngine::get()->playSource(m_AudioID); } } m_State = newSoundState; }
void SoundNode::connectDisplay() { if (!AudioEngine::get()) { throw Exception(AVG_ERR_UNSUPPORTED, "Sound nodes can only be created if audio is not disabled."); } checkReload(); AreaNode::connectDisplay(); long long curTime = Player::get()->getFrameTime(); if (m_State != Unloaded) { startDecoding(); m_StartTime = curTime; m_PauseTime = 0; } if (m_State == Paused) { m_PauseStartTime = curTime; } }