Bug 1477477 - Add preference for autoplaying muted media. r=cpearce
authorTom Schuster <evilpies@gmail.com>
Sun, 22 Jul 2018 15:21:48 +0200
changeset 821325 e384aedb30b603ca951dc1bfba92b19875a5f92d
parent 821324 91f5766f581bed9e152b6f924dabb76dbb89f816
child 821326 54c01f0092e1f1edcede61fd08042e99d76d5c30
child 821330 844d72890680d8656bd5d0ed1ffaadb9ec243dcc
push id117062
push userxquan@mozilla.com
push dateSun, 22 Jul 2018 23:52:16 +0000
reviewerscpearce
bugs1477477
milestone63.0a1
Bug 1477477 - Add preference for autoplaying muted media. r=cpearce
dom/media/AutoplayPolicy.cpp
modules/libpref/init/all.js
--- a/dom/media/AutoplayPolicy.cpp
+++ b/dom/media/AutoplayPolicy.cpp
@@ -110,17 +110,18 @@ AutoplayPolicy::IsAllowedToPlay(const HT
     // If element is blessed, it would always be allowed to play().
     return (autoplayDefault == nsIAutoplay::ALLOWED ||
             aElement.IsBlessed() ||
             EventStateManager::IsHandlingUserInput())
               ? nsIAutoplay::ALLOWED : nsIAutoplay::BLOCKED;
   }
 
   // Muted content
-  if (aElement.Volume() == 0.0 || aElement.Muted()) {
+  if ((aElement.Volume() == 0.0 || aElement.Muted()) &&
+      Preferences::GetBool("media.autoplay.allow-muted", true)) {
     return nsIAutoplay::ALLOWED;
   }
 
   if (IsWindowAllowedToPlay(aElement.OwnerDoc()->GetInnerWindow())) {
     return nsIAutoplay::ALLOWED;
   }
 
   return autoplayDefault;
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -565,16 +565,19 @@ pref("media.recorder.video.frame_drops",
 
 // Whether to autostart a media element with an |autoplay| attribute.
 // ALLOWED=0, BLOCKED=1, PROMPT=2, defined in dom/media/Autoplay.idl
 pref("media.autoplay.default", 0);
 
 // By default, don't block WebAudio from playing automatically.
 pref("media.autoplay.block-webaudio", false);
 
+// By default, don't block muted media from playing automatically.
+pref("media.autoplay.allow-muted", true);
+
 // If "media.autoplay.default" is not ALLOWED, and this pref is true,
 // then audible media would only be allowed to autoplay after website has
 // been activated by specific user gestures, but non-audible
 // media won't be restricted.
 #ifdef NIGHTLY_BUILD
 pref("media.autoplay.enabled.user-gestures-needed", false);
 #endif