diff --git a/interface/resources/sounds/snap.wav b/interface/resources/sounds/snap.wav index bb562e1db9..e5b86c0c71 100644 Binary files a/interface/resources/sounds/snap.wav and b/interface/resources/sounds/snap.wav differ diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d7005f2c0d..fbf28a8d99 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -594,7 +594,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _aboutToQuit(false), _notifiedPacketVersionMismatchThisDomain(false), _maxOctreePPS(maxOctreePacketsPerSecond.get()), - _lastFaceTrackerUpdate(0) + _lastFaceTrackerUpdate(0), + _snapshotSound(nullptr) { auto steamClient = PluginManager::getInstance()->getSteamClientPlugin(); setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning())); @@ -1454,6 +1455,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return entityServerNode && !isPhysicsEnabled(); }); + QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); + _snapshotSound = DependencyManager::get()->getSound(QUrl::fromLocalFile(inf.absoluteFilePath())); + QVariant testProperty = property(hifi::properties::TEST); qDebug() << testProperty; if (testProperty.isValid()) { @@ -1776,12 +1780,17 @@ void Application::cleanupBeforeQuit() { // stop QML DependencyManager::destroy(); + if (_snapshotSoundInjector != nullptr) { + _snapshotSoundInjector->stop(); + } + // stop audio after QML, as there are unexplained audio crashes originating in qtwebengine // stop the AudioClient, synchronously QMetaObject::invokeMethod(DependencyManager::get().data(), "stop", Qt::BlockingQueuedConnection); + // destroy Audio so it and its threads have a chance to go down safely DependencyManager::destroy(); DependencyManager::destroy(); @@ -6406,15 +6415,24 @@ void Application::loadAddAvatarBookmarkDialog() const { } void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRatio) { - postLambdaEvent([notify, includeAnimated, aspectRatio, this] { - QMediaPlayer* player = new QMediaPlayer(); - QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); - player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); - player->play(); + + //keep sound thread out of event loop scope + AudioInjectorOptions options; + options.localOnly = true; + options.stereo = true; + + if (_snapshotSoundInjector) { + _snapshotSoundInjector->setOptions(options); + _snapshotSoundInjector->restart(); + } else { + QByteArray samples = _snapshotSound->getByteArray(); + _snapshotSoundInjector = AudioInjector::playSound(samples, options); + } + + postLambdaEvent([notify, includeAnimated, aspectRatio, this] { // Get a screenshot and save it QString path = Snapshot::saveSnapshot(getActiveDisplayPlugin()->getScreenshot(aspectRatio)); - // If we're not doing an animated snapshot as well... if (!includeAnimated || !(SnapshotAnimated::alsoTakeAnimatedSnapshot.get())) { // Tell the dependency manager that the capture of the still snapshot has taken place. @@ -6425,6 +6443,7 @@ void Application::takeSnapshot(bool notify, bool includeAnimated, float aspectRa } }); } + void Application::shareSnapshot(const QString& path, const QUrl& href) { postLambdaEvent([path, href] { // not much to do here, everything is done in snapshot code... diff --git a/interface/src/Application.h b/interface/src/Application.h index 55c8303905..dff1de2860 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -73,6 +73,7 @@ #include #include +#include "Sound.h" class OffscreenGLCanvas; class GLCanvas; @@ -80,6 +81,7 @@ class FaceTracker; class MainWindow; class AssetUpload; class CompositorHelper; +class AudioInjector; namespace controller { class StateController; @@ -683,6 +685,8 @@ private: QTimer _addAssetToWorldErrorTimer; FileScriptingInterface* _fileDownload; + AudioInjector* _snapshotSoundInjector { nullptr }; + SharedSoundPointer _snapshotSound; };