mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-20 00:11:34 +00:00
Pause both audio and video playback when the game is minimized (feature #4944)
This commit is contained in:
parent
3d6fd2818f
commit
2254256db9
11 changed files with 99 additions and 4 deletions
|
@ -243,6 +243,7 @@
|
||||||
Feature #4882: Support for NiPalette node
|
Feature #4882: Support for NiPalette node
|
||||||
Feature #4887: Add openmw command option to set initial random seed
|
Feature #4887: Add openmw command option to set initial random seed
|
||||||
Feature #4890: Make Distant Terrain configurable
|
Feature #4890: Make Distant Terrain configurable
|
||||||
|
Feature #4944: Pause audio when OpenMW is minimized
|
||||||
Feature #4958: Support eight blood types
|
Feature #4958: Support eight blood types
|
||||||
Feature #4962: Add casting animations for magic items
|
Feature #4962: Add casting animations for magic items
|
||||||
Feature #4968: Scalable UI widget skins
|
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),
|
// 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)
|
// and destroyed widgets will not be deleted (not fixed yet, https://github.com/MyGUI/mygui/issues/21)
|
||||||
if (!mEnvironment.getInputManager()->isWindowVisible())
|
if (!mEnvironment.getInputManager()->isWindowVisible())
|
||||||
|
{
|
||||||
|
mEnvironment.getSoundManager()->pausePlayback();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mEnvironment.getSoundManager()->resumePlayback();
|
||||||
|
|
||||||
// sound
|
// sound
|
||||||
if (mUseSound)
|
if (mUseSound)
|
||||||
|
|
|
@ -174,6 +174,9 @@ namespace MWBase
|
||||||
virtual void resumeSounds(const std::string& blockerId) = 0;
|
virtual void resumeSounds(const std::string& blockerId) = 0;
|
||||||
///< Resumes all previously paused sounds.
|
///< Resumes all previously paused sounds.
|
||||||
|
|
||||||
|
virtual void pausePlayback() = 0;
|
||||||
|
virtual void resumePlayback() = 0;
|
||||||
|
|
||||||
virtual void update(float duration) = 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;
|
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();
|
mPlayer->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoWidget::pause()
|
||||||
|
{
|
||||||
|
mPlayer->pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidget::resume()
|
||||||
|
{
|
||||||
|
mPlayer->play();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VideoWidget::isPaused() const
|
||||||
|
{
|
||||||
|
return mPlayer->isPaused();
|
||||||
|
}
|
||||||
|
|
||||||
bool VideoWidget::hasAudioStream()
|
bool VideoWidget::hasAudioStream()
|
||||||
{
|
{
|
||||||
return mPlayer->hasAudioStream();
|
return mPlayer->hasAudioStream();
|
||||||
|
|
|
@ -47,6 +47,10 @@ namespace MWGui
|
||||||
/// Stop video and free resources (done automatically on destruction)
|
/// Stop video and free resources (done automatically on destruction)
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
void pause();
|
||||||
|
void resume();
|
||||||
|
bool isPaused() const;
|
||||||
|
|
||||||
/// Adjust the coordinates of this video widget relative to its parent,
|
/// Adjust the coordinates of this video widget relative to its parent,
|
||||||
/// based on the dimensions of the playing video.
|
/// based on the dimensions of the playing video.
|
||||||
/// @param stretch Stretch the video to fill the whole screen? If false,
|
/// @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);
|
MWBase::Environment::get().getInputManager()->update(dt, true, false);
|
||||||
|
|
||||||
if (!MWBase::Environment::get().getInputManager()->isWindowVisible())
|
if (!MWBase::Environment::get().getInputManager()->isWindowVisible())
|
||||||
|
{
|
||||||
|
mVideoWidget->pause();
|
||||||
OpenThreads::Thread::microSleep(5000);
|
OpenThreads::Thread::microSleep(5000);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (mVideoWidget->isPaused())
|
||||||
|
mVideoWidget->resume();
|
||||||
|
|
||||||
mViewer->eventTraversal();
|
mViewer->eventTraversal();
|
||||||
mViewer->updateTraversal();
|
mViewer->updateTraversal();
|
||||||
mViewer->renderingTraversals();
|
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)
|
void OpenAL_Output::resumeSounds(int types)
|
||||||
{
|
{
|
||||||
std::vector<ALuint> sources;
|
std::vector<ALuint> sources;
|
||||||
|
|
|
@ -92,6 +92,9 @@ namespace MWSound
|
||||||
virtual void pauseSounds(int types);
|
virtual void pauseSounds(int types);
|
||||||
virtual void resumeSounds(int types);
|
virtual void resumeSounds(int types);
|
||||||
|
|
||||||
|
virtual void pauseActiveDevice();
|
||||||
|
virtual void resumeActiveDevice();
|
||||||
|
|
||||||
OpenAL_Output(SoundManager &mgr);
|
OpenAL_Output(SoundManager &mgr);
|
||||||
virtual ~OpenAL_Output();
|
virtual ~OpenAL_Output();
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,6 +62,9 @@ namespace MWSound
|
||||||
virtual void pauseSounds(int types) = 0;
|
virtual void pauseSounds(int types) = 0;
|
||||||
virtual void resumeSounds(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& operator=(const Sound_Output &rhs);
|
||||||
Sound_Output(const Sound_Output &rhs);
|
Sound_Output(const Sound_Output &rhs);
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ namespace MWSound
|
||||||
, mListenerUp(0,0,1)
|
, mListenerUp(0,0,1)
|
||||||
, mUnderwaterSound(nullptr)
|
, mUnderwaterSound(nullptr)
|
||||||
, mNearWaterSound(nullptr)
|
, mNearWaterSound(nullptr)
|
||||||
|
, mPlaybackPaused(false)
|
||||||
{
|
{
|
||||||
mMasterVolume = Settings::Manager::getFloat("master volume", "Sound");
|
mMasterVolume = Settings::Manager::getFloat("master volume", "Sound");
|
||||||
mMasterVolume = std::min(std::max(mMasterVolume, 0.0f), 1.0f);
|
mMasterVolume = std::min(std::max(mMasterVolume, 0.0f), 1.0f);
|
||||||
|
@ -856,7 +857,6 @@ namespace MWSound
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SoundManager::pauseSounds(const std::string& blockerId, int types)
|
void SoundManager::pauseSounds(const std::string& blockerId, int types)
|
||||||
{
|
{
|
||||||
if(mOutput->isInitialized())
|
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)
|
void SoundManager::updateRegionSound(float duration)
|
||||||
{
|
{
|
||||||
static float sTimeToNextEnvSound = 0.0f;
|
static float sTimeToNextEnvSound = 0.0f;
|
||||||
|
@ -1209,7 +1227,7 @@ namespace MWSound
|
||||||
|
|
||||||
void SoundManager::update(float duration)
|
void SoundManager::update(float duration)
|
||||||
{
|
{
|
||||||
if(!mOutput->isInitialized())
|
if(!mOutput->isInitialized() || mPlaybackPaused)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
updateSounds(duration);
|
updateSounds(duration);
|
||||||
|
@ -1408,5 +1426,6 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
mActiveTracks.clear();
|
mActiveTracks.clear();
|
||||||
mPausedSoundTypes.clear();
|
mPausedSoundTypes.clear();
|
||||||
|
mPlaybackPaused = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,9 @@ namespace MWSound
|
||||||
Sound *mUnderwaterSound;
|
Sound *mUnderwaterSound;
|
||||||
Sound *mNearWaterSound;
|
Sound *mNearWaterSound;
|
||||||
|
|
||||||
|
std::string mNextMusic;
|
||||||
|
bool mPlaybackPaused;
|
||||||
|
|
||||||
Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound);
|
Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound);
|
||||||
|
|
||||||
Sound_Buffer *lookupSound(const std::string &soundId) const;
|
Sound_Buffer *lookupSound(const std::string &soundId) const;
|
||||||
|
@ -134,8 +137,6 @@ namespace MWSound
|
||||||
void updateWaterSound(float duration);
|
void updateWaterSound(float duration);
|
||||||
void updateMusic(float duration);
|
void updateMusic(float duration);
|
||||||
|
|
||||||
std::string mNextMusic;
|
|
||||||
|
|
||||||
float volumeFromType(Type type) const;
|
float volumeFromType(Type type) const;
|
||||||
|
|
||||||
SoundManager(const SoundManager &rhs);
|
SoundManager(const SoundManager &rhs);
|
||||||
|
@ -250,6 +251,9 @@ namespace MWSound
|
||||||
virtual void resumeSounds(const std::string& blockerId);
|
virtual void resumeSounds(const std::string& blockerId);
|
||||||
///< Resumes all previously paused sounds.
|
///< Resumes all previously paused sounds.
|
||||||
|
|
||||||
|
virtual void pausePlayback();
|
||||||
|
virtual void resumePlayback();
|
||||||
|
|
||||||
virtual void update(float duration);
|
virtual void update(float duration);
|
||||||
|
|
||||||
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater);
|
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater);
|
||||||
|
|
Loading…
Reference in a new issue