Forráskód Böngészése

chore: video playback should respect automute settings, fixes #456

Almamu 7 hónapja
szülő
commit
898b3ee368

+ 4 - 0
src/WallpaperEngine/Audio/AudioContext.cpp

@@ -27,4 +27,8 @@ Application::ApplicationContext& AudioContext::getApplicationContext () const {
 Drivers::Recorders::PlaybackRecorder& AudioContext::getRecorder () const {
     return this->m_driver.getRecorder ();
 }
+
+Drivers::AudioDriver& AudioContext::getDriver () const {
+    return this->m_driver;
+}
 } // namespace WallpaperEngine::Audio

+ 5 - 0
src/WallpaperEngine/Audio/AudioContext.h

@@ -56,6 +56,11 @@ class AudioContext {
      */
     [[nodiscard]] Drivers::Recorders::PlaybackRecorder& getRecorder () const;
 
+    /**
+     * @return The audio driver used to playback and record audio
+     */
+    [[nodiscard]] Drivers::AudioDriver& getDriver () const;
+
   private:
     /** The audio driver in use */
     Drivers::AudioDriver& m_driver;

+ 13 - 0
src/WallpaperEngine/Render/Wallpapers/CVideo.cpp

@@ -44,6 +44,7 @@ CVideo::CVideo (
     mpv_set_option (this->m_mpv, "volume", MPV_FORMAT_DOUBLE, &volume);
 
     if (!this->getContext ().getApp ().getContext ().settings.audio.enabled) {
+        this->m_muted = true;
         mpv_set_option_string (this->m_mpv, "mute", "yes");
     }
 
@@ -89,6 +90,18 @@ void CVideo::setSize (const int width, const int height) {
 }
 
 void CVideo::renderFrame (const glm::ivec4& viewport) {
+    // ensure the video's audio follows audio detection rules
+    if (this->getContext ().getApp ().getContext ().settings.audio.enabled &&
+        this->m_muted != this->getAudioContext ().getDriver ().getAudioDetector ().anythingPlaying ()) {
+        this->m_muted = !this->m_muted;
+
+        const char* mutecommand [] = {
+            "set", "mute", this->m_muted ? "yes" : "no", nullptr
+        };
+
+        mpv_command (this->m_mpv, mutecommand);
+    }
+
     // read any and all the events available
     while (this->m_mpv) {
         const mpv_event* event = mpv_wait_event (this->m_mpv, 0);

+ 1 - 0
src/WallpaperEngine/Render/Wallpapers/CVideo.h

@@ -33,5 +33,6 @@ class CVideo final : public CWallpaper {
     bool m_paused = false;
     int64_t m_width = 16;
     int64_t m_height = 16;
+    bool m_muted = false;
 };
 } // namespace WallpaperEngine::Render::Wallpapers