diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 855404fb1f23..15420619a822 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -5678,7 +5678,9 @@ void HTMLMediaElement::PlaybackEnded() { mAutoplaying = true; } - mMediaControlKeyListener->StopIfNeeded(); + if (StaticPrefs::media_mediacontrol_stopcontrol_aftermediaends()) { + mMediaControlKeyListener->StopIfNeeded(); + } DispatchAsyncEvent(u"ended"_ns); } diff --git a/dom/media/mediacontrol/tests/browser_stop_control_after_media_reaches_to_end.js b/dom/media/mediacontrol/tests/browser_stop_control_after_media_reaches_to_end.js index 35e3be081fd4..76e4f96fcc21 100644 --- a/dom/media/mediacontrol/tests/browser_stop_control_after_media_reaches_to_end.js +++ b/dom/media/mediacontrol/tests/browser_stop_control_after_media_reaches_to_end.js @@ -2,6 +2,12 @@ const PAGE_URL = "https://example.com/browser/dom/media/mediacontrol/tests/file_non_looping_media.html"; +add_task(async function setupTestingPref() { + await SpecialPowers.pushPrefEnv({ + set: [["media.mediacontrol.stopcontrol.aftermediaends", true]], + }); +}); + /** * This test is used to ensure that we would stop controlling media after it * reaches to the end. diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 5328793639b2..89f4d9a3700d 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -7565,6 +7565,13 @@ value: 60000 mirror: always +# If this pref is on, we would stop controlling media after it reaches to the +# end. +- name: media.mediacontrol.stopcontrol.aftermediaends + type: bool + value: true + 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