Diff
Modified: trunk/LayoutTests/ChangeLog (187256 => 187257)
--- trunk/LayoutTests/ChangeLog 2015-07-23 22:02:07 UTC (rev 187256)
+++ trunk/LayoutTests/ChangeLog 2015-07-23 22:06:56 UTC (rev 187257)
@@ -1,3 +1,14 @@
+2015-07-19 Matt Rajca <[email protected]>
+
+ Media Session: add support for ducking media elements
+ https://bugs.webkit.org/show_bug.cgi?id=147089
+
+ Reviewed by Eric Carlson.
+
+ * media/session/transient-interruptions-expected.txt: Added.
+ * media/session/transient-interruptions.html: Added.
+ * platform/mac/TestExpectations: Media Session support is disabled by default.
+
2015-07-23 Devin Rousso <[email protected]>
Web Inspector: Add a function to CSSCompletions to get a list of supported system fonts
Added: trunk/LayoutTests/media/session/transient-interruptions-expected.txt (0 => 187257)
--- trunk/LayoutTests/media/session/transient-interruptions-expected.txt (rev 0)
+++ trunk/LayoutTests/media/session/transient-interruptions-expected.txt 2015-07-23 22:06:56 UTC (rev 187257)
@@ -0,0 +1,18 @@
+'Transient' interruption events should duck audio for 'Content' media sessions.
+
+
+Waiting for Content media to begin playing.
+EVENT(canplaythrough)
+Media began playing.
+EXPECTED (internals.mediaSessionCurrentState(session) == 'active') OK
+EXPECTED (internals.mediaElementPlayerVolume(document.getElementById("video")) == '1') OK
+Sending 'Transient' start-of-interruption notification.
+RUN(internals.sendMediaSessionStartOfInterruptionNotification("transient"))
+EXPECTED (internals.mediaSessionCurrentState(session) == 'interrupted') OK
+EXPECTED (internals.mediaElementPlayerVolume(document.getElementById("video")) == '0.25') OK
+Sending 'Transient' end-of-interruption notification.
+RUN(internals.sendMediaSessionEndOfInterruptionNotification("transient"))
+EXPECTED (internals.mediaSessionCurrentState(session) == 'active') OK
+EXPECTED (internals.mediaElementPlayerVolume(document.getElementById("video")) == '1') OK
+END OF TEST
+
Added: trunk/LayoutTests/media/session/transient-interruptions.html (0 => 187257)
--- trunk/LayoutTests/media/session/transient-interruptions.html (rev 0)
+++ trunk/LayoutTests/media/session/transient-interruptions.html 2015-07-23 22:06:56 UTC (rev 187257)
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+ <script src=""
+ <script type="text/_javascript_">
+ var session;
+
+ function runTest()
+ {
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ window.jsTestIsAsync = true;
+
+ session = new MediaSession("content");
+
+ consoleWrite("Waiting for Content media to begin playing.")
+ var video = document.getElementById("video");
+ waitForEvent('canplaythrough', beginPlaying);
+ video.src = "" "../content/counting");
+ video.session = session;
+ video.volume = 1;
+ video._onplaying_ = beganPlaying;
+ }
+
+ function beginPlaying(event)
+ {
+ document.getElementById("video").play();
+ }
+
+ function beganPlaying(event)
+ {
+ consoleWrite("Media began playing.");
+
+ if (window.internals) {
+ testExpected('internals.mediaSessionCurrentState(session)', "active");
+ testExpected('internals.mediaElementPlayerVolume(document.getElementById("video"))', 1);
+
+ consoleWrite("Sending 'Transient' start-of-interruption notification.");
+ run('internals.sendMediaSessionStartOfInterruptionNotification("transient")');
+
+ testExpected('internals.mediaSessionCurrentState(session)', "interrupted");
+ testExpected('internals.mediaElementPlayerVolume(document.getElementById("video"))', 0.25);
+
+ consoleWrite("Sending 'Transient' end-of-interruption notification.");
+ run('internals.sendMediaSessionEndOfInterruptionNotification("transient")');
+
+ testExpected('internals.mediaSessionCurrentState(session)', "active");
+ testExpected('internals.mediaElementPlayerVolume(document.getElementById("video"))', 1);
+ }
+
+ endTest();
+ }
+ </script>
+</head>
+<body _onload_="runTest()">
+ <p>'Transient' interruption events should duck audio for 'Content' media sessions.</p>
+ <video id="video" />
+</body>
+</html>
Modified: trunk/LayoutTests/platform/mac/TestExpectations (187256 => 187257)
--- trunk/LayoutTests/platform/mac/TestExpectations 2015-07-23 22:02:07 UTC (rev 187256)
+++ trunk/LayoutTests/platform/mac/TestExpectations 2015-07-23 22:06:56 UTC (rev 187257)
@@ -996,6 +996,7 @@
media/session/content-interruptions.html
media/session/controls-existence.html
media/session/default-session.html
+media/session/transient-interruptions.html
# This test requires generation of progress events during loading
webkit.org/b/100984 media/progress-events-generated-correctly.html [ Failure ]
Modified: trunk/Source/WebCore/ChangeLog (187256 => 187257)
--- trunk/Source/WebCore/ChangeLog 2015-07-23 22:02:07 UTC (rev 187256)
+++ trunk/Source/WebCore/ChangeLog 2015-07-23 22:06:56 UTC (rev 187257)
@@ -1,3 +1,20 @@
+2015-07-19 Matt Rajca <[email protected]>
+
+ Media Session: add support for ducking media elements
+ https://bugs.webkit.org/show_bug.cgi?id=147089
+
+ Reviewed by Eric Carlson.
+
+ Test: media/session/transient-interruptions.html
+
+ * Modules/mediasession/MediaSession.cpp:
+ (WebCore::MediaSession::handleDuckInterruption): Duck the active media elements.
+ (WebCore::MediaSession::handleUnduckInterruption): Unduck the active media elements.
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::updateVolume): Lower the volume of media elements to 25% when ducked (constant determined empirically).
+ (WebCore::HTMLMediaElement::setShouldDuck): Call updateVolume to change the volume of the underlying media player.
+ * html/HTMLMediaElement.h:
+
2015-07-23 Matt Rajca <[email protected]>
Media Session: add infrastructure for testing ducking https://bugs.webkit.org/show_bug.cgi?id=147080
Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp (187256 => 187257)
--- trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp 2015-07-23 22:02:07 UTC (rev 187256)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp 2015-07-23 22:06:56 UTC (rev 187257)
@@ -240,14 +240,16 @@
void MediaSession::handleDuckInterruption()
{
- // FIXME: Duck media elements.
+ for (auto* element : m_activeParticipatingElements)
+ element->setShouldDuck(true);
m_currentState = State::Interrupted;
}
void MediaSession::handleUnduckInterruption()
{
- // FIXME: Unduck media elements.
+ for (auto* element : m_activeParticipatingElements)
+ element->setShouldDuck(false);
m_currentState = State::Active;
}
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (187256 => 187257)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2015-07-23 22:02:07 UTC (rev 187256)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2015-07-23 22:06:56 UTC (rev 187257)
@@ -4652,6 +4652,11 @@
shouldMute = m_mediaController->muted() || (page && page->isMuted());
}
+#if ENABLE(MEDIA_SESSION)
+ if (m_shouldDuck)
+ volumeMultiplier *= 0.25;
+#endif
+
m_player->setMuted(shouldMute);
m_player->setVolume(m_volume * volumeMultiplier);
}
@@ -6534,6 +6539,15 @@
m_kind = session.kind();
}
+void HTMLMediaElement::setShouldDuck(bool duck)
+{
+ if (m_shouldDuck == duck)
+ return;
+
+ m_shouldDuck = duck;
+ updateVolume();
+}
+
#endif
void HTMLMediaElement::allowsMediaDocumentInlinePlaybackChanged()
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (187256 => 187257)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2015-07-23 22:02:07 UTC (rev 187256)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2015-07-23 22:06:56 UTC (rev 187257)
@@ -427,6 +427,8 @@
MediaSession* session() const;
void setSession(MediaSession*);
+
+ void setShouldDuck(bool);
#endif
#if ENABLE(MEDIA_SOURCE)
@@ -822,6 +824,7 @@
#if ENABLE(MEDIA_SESSION)
String m_kind;
RefPtr<MediaSession> m_session;
+ bool m_shouldDuck { false };
#endif
#if ENABLE(MEDIA_SOURCE)