Pause both audio and video playback when the game is minimized (feature #4944)

pull/2749/head
Andrei Kortunov 5 years ago
parent 3d6fd2818f
commit 2254256db9

@ -243,6 +243,7 @@
Feature #4882: Support for NiPalette node
Feature #4887: Add openmw command option to set initial random seed
Feature #4890: Make Distant Terrain configurable
Feature #4944: Pause audio when OpenMW is minimized
Feature #4958: Support eight blood types
Feature #4962: Add casting animations for magic items
Feature #4968: Scalable UI widget skins

@ -96,7 +96,12 @@ bool OMW::Engine::frame(float frametime)
// If we are not currently rendering, then RenderItems will not be reused resulting in a memory leak upon changing widget textures (fixed in MyGUI 3.3.2),
// and destroyed widgets will not be deleted (not fixed yet, https://github.com/MyGUI/mygui/issues/21)
if (!mEnvironment.getInputManager()->isWindowVisible())
{
mEnvironment.getSoundManager()->pausePlayback();
return false;
}
else
mEnvironment.getSoundManager()->resumePlayback();
// sound
if (mUseSound)

@ -174,6 +174,9 @@ namespace MWBase
virtual void resumeSounds(const std::string& blockerId) = 0;
///< Resumes all previously paused sounds.
virtual void pausePlayback() = 0;
virtual void resumePlayback() = 0;
virtual void update(float duration) = 0;
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater) = 0;

@ -76,6 +76,21 @@ void VideoWidget::stop()
mPlayer->close();
}
void VideoWidget::pause()
{
mPlayer->pause();
}
void VideoWidget::resume()
{
mPlayer->play();
}
bool VideoWidget::isPaused() const
{
return mPlayer->isPaused();
}
bool VideoWidget::hasAudioStream()
{
return mPlayer->hasAudioStream();

@ -47,6 +47,10 @@ namespace MWGui
/// Stop video and free resources (done automatically on destruction)
void stop();
void pause();
void resume();
bool isPaused() const;
/// Adjust the coordinates of this video widget relative to its parent,
/// based on the dimensions of the playing video.
/// @param stretch Stretch the video to fill the whole screen? If false,

@ -1905,9 +1905,15 @@ namespace MWGui
MWBase::Environment::get().getInputManager()->update(dt, true, false);
if (!MWBase::Environment::get().getInputManager()->isWindowVisible())
{
mVideoWidget->pause();
OpenThreads::Thread::microSleep(5000);
}
else
{
if (mVideoWidget->isPaused())
mVideoWidget->resume();
mViewer->eventTraversal();
mViewer->updateTraversal();
mViewer->renderingTraversals();

@ -1454,6 +1454,38 @@ void OpenAL_Output::pauseSounds(int types)
}
}
void OpenAL_Output::pauseActiveDevice()
{
if (mDevice == nullptr)
return;
if(alcIsExtensionPresent(mDevice, "ALC_SOFT_PAUSE_DEVICE"))
{
LPALCDEVICEPAUSESOFT alcDevicePauseSOFT = 0;
getALCFunc(alcDevicePauseSOFT, mDevice, "alcDevicePauseSOFT");
alcDevicePauseSOFT(mDevice);
getALCError(mDevice);
}
alListenerf(AL_GAIN, 0.0f);
}
void OpenAL_Output::resumeActiveDevice()
{
if (mDevice == nullptr)
return;
if(alcIsExtensionPresent(mDevice, "ALC_SOFT_PAUSE_DEVICE"))
{
LPALCDEVICERESUMESOFT alcDeviceResumeSOFT = 0;
getALCFunc(alcDeviceResumeSOFT, mDevice, "alcDeviceResumeSOFT");
alcDeviceResumeSOFT(mDevice);
getALCError(mDevice);
}
alListenerf(AL_GAIN, 1.0f);
}
void OpenAL_Output::resumeSounds(int types)
{
std::vector<ALuint> sources;

@ -92,6 +92,9 @@ namespace MWSound
virtual void pauseSounds(int types);
virtual void resumeSounds(int types);
virtual void pauseActiveDevice();
virtual void resumeActiveDevice();
OpenAL_Output(SoundManager &mgr);
virtual ~OpenAL_Output();
};

@ -62,6 +62,9 @@ namespace MWSound
virtual void pauseSounds(int types) = 0;
virtual void resumeSounds(int types) = 0;
virtual void pauseActiveDevice() = 0;
virtual void resumeActiveDevice() = 0;
Sound_Output& operator=(const Sound_Output &rhs);
Sound_Output(const Sound_Output &rhs);

@ -52,6 +52,7 @@ namespace MWSound
, mListenerUp(0,0,1)
, mUnderwaterSound(nullptr)
, mNearWaterSound(nullptr)
, mPlaybackPaused(false)
{
mMasterVolume = Settings::Manager::getFloat("master volume", "Sound");
mMasterVolume = std::min(std::max(mMasterVolume, 0.0f), 1.0f);
@ -856,7 +857,6 @@ namespace MWSound
return false;
}
void SoundManager::pauseSounds(const std::string& blockerId, int types)
{
if(mOutput->isInitialized())
@ -887,6 +887,24 @@ namespace MWSound
}
}
void SoundManager::pausePlayback()
{
if (mPlaybackPaused)
return;
mPlaybackPaused = true;
mOutput->pauseActiveDevice();
}
void SoundManager::resumePlayback()
{
if (!mPlaybackPaused)
return;
mPlaybackPaused = false;
mOutput->resumeActiveDevice();
}
void SoundManager::updateRegionSound(float duration)
{
static float sTimeToNextEnvSound = 0.0f;
@ -1209,7 +1227,7 @@ namespace MWSound
void SoundManager::update(float duration)
{
if(!mOutput->isInitialized())
if(!mOutput->isInitialized() || mPlaybackPaused)
return;
updateSounds(duration);
@ -1408,5 +1426,6 @@ namespace MWSound
}
mActiveTracks.clear();
mPausedSoundTypes.clear();
mPlaybackPaused = false;
}
}

@ -112,6 +112,9 @@ namespace MWSound
Sound *mUnderwaterSound;
Sound *mNearWaterSound;
std::string mNextMusic;
bool mPlaybackPaused;
Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound);
Sound_Buffer *lookupSound(const std::string &soundId) const;
@ -134,8 +137,6 @@ namespace MWSound
void updateWaterSound(float duration);
void updateMusic(float duration);
std::string mNextMusic;
float volumeFromType(Type type) const;
SoundManager(const SoundManager &rhs);
@ -250,6 +251,9 @@ namespace MWSound
virtual void resumeSounds(const std::string& blockerId);
///< Resumes all previously paused sounds.
virtual void pausePlayback();
virtual void resumePlayback();
virtual void update(float duration);
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater);

Loading…
Cancel
Save