-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't allow playback to start when in the background and interrupted …
…by the system https://bugs.webkit.org/show_bug.cgi?id=269081 rdar://117928506 Reviewed by Jer Noble. Don't allow playback to begin when WebKit is in the background and has also been interrupted by the audio session. This can happen, for example, when playback is started from Control Center on the lock screen and the user switches to the camera app and activates the video camera. Allowing playback activates WebKit's AVAudioSession and prevents the camera app from using the volume buttons to trigger start/stop recording. * LayoutTests/media/video-playback-system-interruption-expected.txt: Added. * LayoutTests/media/video-playback-system-interruption.html: Added. * Source/WebCore/html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::couldPlayIfEnoughData const): Return false if the element needs an active audio session and it was paused by a system interruption. * Source/WebCore/platform/audio/PlatformMediaSession.cpp: Keep a vector of interruption types instead of an interruption count so we know the type of the most recent interruption. (WebCore::PlatformMediaSession::interruptionType const): Return the type of the most recent interruption, not the first. (WebCore::PlatformMediaSession::beginInterruption): Update for interruption stack. (WebCore::PlatformMediaSession::endInterruption): Ditto. (WebCore::PlatformMediaSession::isPlayingToWirelessPlaybackTargetChanged): Can no longer save and restore the interruption count, but the issue that caused the change appears to have been fixed. (WebCore::PlatformMediaSession::blockedBySystemInterruption const): * Source/WebCore/platform/audio/PlatformMediaSession.h: (WebCore::PlatformMediaSession::interruptionCount const): (WebCore::PlatformMediaSession::interruptionType const): Deleted. Canonical link: https://commits.webkit.org/274438@main
- Loading branch information
1 parent
b0a7f8b
commit 537043c
Showing
7 changed files
with
98 additions
and
18 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
LayoutTests/media/video-playback-system-interruption-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
RUN(internals.setMediaElementRestrictions(video, 'NoRestrictions')) | ||
RUN(internals.beginMediaSessionInterruption("EnteringBackground")) | ||
RUN(internals.beginMediaSessionInterruption("System")) | ||
RUN(video.volume = 0.1) | ||
RUN(video.src = findMediaFile("video", "content/audio-tracks")) | ||
EVENT(canplaythrough) | ||
EXPECTED (video.paused == 'true') OK | ||
EXPECTED (internals.mediaSessionState(video) == 'Interrupted') OK | ||
RUN(internals.endMediaSessionInterruption("MayResumePlaying")) | ||
EVENT(playing) | ||
EXPECTED (internals.mediaSessionState(video) != 'Interrupted') OK | ||
END OF TEST | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="media-file.js"></script> | ||
<script src="video-test.js"></script> | ||
<script> | ||
|
||
window.addEventListener('load', async event => { | ||
if (!window.internals) { | ||
failTest('This test must be run in DumpRenderTree or WebKitTestRunner.'); | ||
return; | ||
} | ||
|
||
findMediaElement(); | ||
run(`internals.setMediaElementRestrictions(video, 'NoRestrictions')`); | ||
run('internals.beginMediaSessionInterruption("EnteringBackground")'); | ||
run('internals.beginMediaSessionInterruption("System")'); | ||
|
||
run('video.volume = 0.1'); | ||
run('video.src = findMediaFile("video", "content/audio-tracks")'); | ||
|
||
waitForEvent('playing', () => { testExpected('internals.mediaSessionState(video)', 'Interrupted', '!=') }); | ||
await waitFor(video, 'canplaythrough'); | ||
|
||
await sleepFor(250); | ||
testExpected('video.paused', true); | ||
testExpected('internals.mediaSessionState(video)', 'Interrupted'); | ||
|
||
run('internals.endMediaSessionInterruption("MayResumePlaying")'); | ||
|
||
// Wait some time before ending the test to ensure the session interruption is cancelled. | ||
endTestLater(); | ||
}); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<video autoplay controls></video> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters