-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] AudioContext is getting suspended when page goes in the backgro…
…und even if navigator.audioSession.type is set to playback https://bugs.webkit.org/show_bug.cgi?id=261554 rdar://115485355 Reviewed by Eric Carlson. Implement isNowPlayingEligible, nowPlayingInfo and selectBestMediaSession to enable NowPlayingInfo handling. Only activated by JS AudioContext(s) are NowPlayingInfo-able if DOM AudioSession type is playback or plabyack and record. Implement canReceiveRemoteControlCommands and didReceiveRemoteControlCommand to be able to play/pause according commands. Update AudioContext::mayResumePlayback to only resume for activated by JS AudioContext(s). Update AudioContext::shouldOverrideBackgroundPlaybackRestriction to be able to continue in the background in case of playback or plabyack and record DOM AudioSession(s). Update bug in PlatformMediaSessionManager::bestEligibleSessionForRemoteControls late time optimization to only add web audio sessions to its list when there is no media element eligible session. If there is an eligible media element session, we do not want to add web audio session to the media session list. * LayoutTests/media/now-playing-webaudio-expected.txt: Added. * LayoutTests/media/now-playing-webaudio.html: Added. * LayoutTests/media/webaudio-background-playback-expected.txt: * LayoutTests/media/webaudio-background-playback.html: * LayoutTests/platform/glib/TestExpectations: * LayoutTests/platform/mac/TestExpectations: * Source/WebCore/Modules/mediasession/NavigatorMediaSession.cpp: (WebCore::NavigatorMediaSession::mediaSessionIfExists): * Source/WebCore/Modules/mediasession/NavigatorMediaSession.h: * Source/WebCore/Modules/webaudio/AudioContext.cpp: (WebCore::AudioContext::AudioContext): (WebCore::AudioContext::mayResumePlayback): (WebCore::AudioContext::canReceiveRemoteControlCommands const): (WebCore::AudioContext::didReceiveRemoteControlCommand): (WebCore::hasPlayBackAudioSession): (WebCore::AudioContext::isNowPlayingEligible const): (WebCore::AudioContext::nowPlayingInfo const): (WebCore::AudioContext::selectBestMediaSession): (WebCore::AudioContext::shouldOverrideBackgroundPlaybackRestriction const): (WebCore::AudioContext::defaultDestinationWillBecomeConnected): * Source/WebCore/Modules/webaudio/AudioContext.h: * Source/WebCore/Modules/webaudio/BaseAudioContext.cpp: (WebCore::BaseAudioContext::setState): * Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp: (WebCore::PlatformMediaSessionManager::bestEligibleSessionForRemoteControls): Canonical link: https://commits.webkit.org/275558@main
- Loading branch information
Showing
12 changed files
with
312 additions
and
18 deletions.
There are no files selected for viewing
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,4 @@ | ||
|
||
PASS AudioContext as the now playing info source | ||
PASS HTMLMediaElement will become the now playing info source over playing AudioContext | ||
|
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,104 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Testing basic video exchange from offerer to receiver</title> | ||
<script src="../resources/testharness.js"></script> | ||
<script src="../resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
function waitFor(delay) | ||
{ | ||
return new Promise(resolve => setTimeout(resolve, delay)); | ||
} | ||
|
||
async function waitForCriteria(test, criteria) | ||
{ | ||
let counter = 0; | ||
while (!criteria() && ++counter < 100) | ||
await waitFor(50); | ||
} | ||
|
||
promise_test(async test => { | ||
if (!window.internals) | ||
return; | ||
|
||
navigator.audioSession.type = "playback"; | ||
|
||
let context = new AudioContext(); | ||
|
||
await waitFor(100); | ||
assert_false(!!internals.nowPlayingState.uniqueIdentifier); | ||
|
||
let oscillator = null; | ||
let gainNode = context.createGain(); | ||
oscillator = context.createOscillator(); | ||
oscillator.type = 'square'; | ||
oscillator.frequency.setValueAtTime(440, context.currentTime); | ||
|
||
oscillator.connect(gainNode); | ||
gainNode.gain.value = 0.1 | ||
|
||
internals.withUserGesture(() => { | ||
context.resume(); | ||
}); | ||
|
||
await waitFor(100); | ||
assert_false(!!internals.nowPlayingState.uniqueIdentifier); | ||
|
||
gainNode.connect(context.destination); | ||
|
||
await waitForCriteria(test, () => { | ||
return !!internals.nowPlayingState.uniqueIdentifier; | ||
}); | ||
assert_true(!!internals.nowPlayingState.uniqueIdentifier, "active now playing"); | ||
|
||
context.suspend(); | ||
|
||
await waitForCriteria(test, () => { | ||
return !internals.nowPlayingState.uniqueIdentifier; | ||
}); | ||
assert_false(!!internals.nowPlayingState.uniqueIdentifier, "inactive now playing"); | ||
|
||
context.resume(); | ||
|
||
await waitForCriteria(test, () => { | ||
return !!internals.nowPlayingState.uniqueIdentifier; | ||
}); | ||
assert_true(!!internals.nowPlayingState.uniqueIdentifier, "active now playing again"); | ||
}, "AudioContext as the now playing info source"); | ||
|
||
promise_test(async test => { | ||
if (!window.internals) | ||
return; | ||
|
||
const identifier = internals.nowPlayingState.uniqueIdentifier; | ||
let mediaElement = document.createElement("audio"); | ||
document.body.appendChild(mediaElement); | ||
|
||
await waitFor(100); | ||
assert_equals(internals.nowPlayingState.uniqueIdentifier, identifier, "AudioContext identifier"); | ||
|
||
await waitFor(100); | ||
assert_equals(internals.nowPlayingState.uniqueIdentifier, identifier, "AudioContext identifier 2"); | ||
|
||
mediaElement.src = "content/test.wav"; | ||
|
||
await waitForCriteria(test, () => { | ||
return internals.nowPlayingState.uniqueIdentifier !== identifier; | ||
}); | ||
assert_not_equals(internals.nowPlayingState.uniqueIdentifier, identifier, "HTMLMediaElement identifier"); | ||
const mediaElementIdentifier = internals.nowPlayingState.uniqueIdentifier | ||
|
||
document.body.removeChild(mediaElement); | ||
|
||
await waitForCriteria(test, () => { | ||
return internals.nowPlayingState.uniqueIdentifier !== mediaElementIdentifier; | ||
}); | ||
assert_equals(internals.nowPlayingState.uniqueIdentifier, identifier, "AudioContext identifier 3"); | ||
}, "HTMLMediaElement will become the now playing info source over playing AudioContext"); | ||
|
||
</script> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
|
||
PASS Ensure WebAudio stops playing in the background when the 'BackgroundProcessPlaybackRestricted' restriction is set | ||
PASS Ensure WebAudio does not stop playing in the background when the 'BackgroundProcessPlaybackRestricted' restriction is set and audioSession type is playback | ||
PASS Ensure WebAudio does not stop playing in the background when the 'BackgroundProcessPlaybackRestricted' restriction is set and audioSession type is play-and-record | ||
PASS Ensure WebAudio stops playing in the background when the 'BackgroundProcessPlaybackRestricted' restriction is set and audioSession type is back to default | ||
|
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
Oops, something went wrong.