From 7dc5318e3bb743655b559385f8543118bd1be43d Mon Sep 17 00:00:00 2001 From: alwu <alwu@mozilla.com> Date: Fri, 6 Mar 2020 17:52:15 +0000 Subject: [PATCH] Bug 1617033 - part8 : add an eligible media duration value to filter out notification sound. r=chunmin Intercepting media control keys would also come up with the virtual control interface in most of platforms, and for the notification sound we don't want either to show the interface or control them. Currently we use 3s as a threshold to filter those short duration media which are possible to be a notification sound. Differential Revision: https://phabricator.services.mozilla.com/D64478 --HG-- extra : moz-landing-system : lando --- dom/html/HTMLMediaElement.cpp | 10 ++++++++++ modules/libpref/init/StaticPrefList.yaml | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index fbbe40db25e7a..6dc50d4feeb61 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -7699,6 +7699,16 @@ void HTMLMediaElement::StartListeningMediaControlEventIfNeeded() { return; } + // In order to filter out notification-ish sound, we use this pref to set the + // eligible media duration to prevent showing media control for those short + // sound. + if (Duration() < + StaticPrefs::media_mediacontrol_eligible_media_duration_s()) { + MEDIACONTROL_LOG("Not listening because media's duration %f is too short.", + Duration()); + return; + } + // As we would like to start listening to media control event again so we // should clear the timer, which is used to stop listening to the event. ClearStopMediaControlTimerIfNeeded(); diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 229b9b0f9aeb7..cb42ffbf5c5e8 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -6888,6 +6888,13 @@ value: 60000 mirror: always +# We would only use media control to control media which duration is longer +# than this value. +- name: media.mediacontrol.eligible.media.duration.s + type: AtomicFloat + value: 3.0f + mirror: always + - name: media.webrtc.platformencoder type: bool #if defined(MOZ_WIDGET_ANDROID) -- GitLab