зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1375119 - Consider a page active if it has running AudioContexts. r=ehsan
MozReview-Commit-ID: IOQ2DY9LoTw --HG-- extra : rebase_source : f47568d3db129ff8d9a484d5b5554f1154d53133
This commit is contained in:
Родитель
dc60e7a8cf
Коммит
b9e645073e
|
@ -4425,6 +4425,11 @@ nsPIDOMWindowInner::SyncStateFromParentWindow()
|
|||
bool
|
||||
nsPIDOMWindowInner::IsPlayingAudio()
|
||||
{
|
||||
for (uint32_t i = 0; i < mAudioContexts.Length(); i++) {
|
||||
if (mAudioContexts[i]->IsRunning()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
RefPtr<AudioChannelService> acs = AudioChannelService::Get();
|
||||
if (!acs) {
|
||||
return false;
|
||||
|
|
|
@ -22,6 +22,7 @@ support-files =
|
|||
file_use_counter_svg_fill_pattern_internal.svg
|
||||
file_use_counter_svg_fill_pattern_data.svg
|
||||
file_webaudioLoop.html
|
||||
file_webaudio_startstop.html
|
||||
plugin.js
|
||||
!/image/test/mochitest/shaver.png
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ var testURLs = [
|
|||
"http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html",
|
||||
"http://mochi.test:8888/browser/dom/base/test/file_audioLoopInIframe.html",
|
||||
"http://mochi.test:8888/browser/dom/base/test/file_pluginAudio.html",
|
||||
"http://mochi.test:8888/browser/dom/base/test/file_webaudioLoop.html",
|
||||
"http://mochi.test:8888/browser/dom/base/test/file_webaudio_startstop.html",
|
||||
];
|
||||
|
||||
// We want to ensure that while audio is being played back, a background tab is
|
||||
|
|
|
@ -8,19 +8,10 @@ var runningPromise = new Promise(resolve => {
|
|||
}
|
||||
};
|
||||
});
|
||||
fetch("audio.ogg").then(response => {
|
||||
return response.arrayBuffer();
|
||||
}).then(ab => {
|
||||
return ac.decodeAudioData(ab);
|
||||
}).then(ab => {
|
||||
var src = ac.createBufferSource();
|
||||
src.buffer = ab;
|
||||
src.loop = true;
|
||||
src.loopStart = 0;
|
||||
src.loopEnd = ab.duration;
|
||||
src.start();
|
||||
src.connect(ac.destination);
|
||||
});
|
||||
|
||||
var osc = ac.createOscillator();
|
||||
osc.connect(ac.destination);
|
||||
osc.start(0);
|
||||
|
||||
var suspendPromise;
|
||||
function suspendAC() {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<script>
|
||||
var ac = new AudioContext();
|
||||
var runningPromise = new Promise(resolve => {
|
||||
ac.onstatechange = event => {
|
||||
if (ac.state == "running") {
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var osc = ac.createOscillator();
|
||||
osc.connect(ac.destination);
|
||||
osc.start(0);
|
||||
osc.stop(osc.context.currentTime + 2.0);
|
||||
|
||||
var suspendPromise;
|
||||
function suspendAC() {
|
||||
runningPromise.then(() => {
|
||||
suspendPromise = ac.suspend();
|
||||
});
|
||||
}
|
||||
|
||||
var resumePromise;
|
||||
function resumeAC() {
|
||||
suspendPromise.then(() => {
|
||||
resumePromise = ac.resume();
|
||||
});
|
||||
}
|
||||
|
||||
function closeAC() {
|
||||
resumePromise.then(() => {
|
||||
ac.close();
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -210,6 +210,7 @@ support-files =
|
|||
file_audioLoop.html
|
||||
file_webaudioLoop.html
|
||||
file_webaudioLoop2.html
|
||||
file_webaudio_startstop.html
|
||||
file_pluginAudio.html
|
||||
file_pluginAudioNonAutoStart.html
|
||||
noaudio.webm
|
||||
|
|
|
@ -492,6 +492,12 @@ AudioContext::Listener()
|
|||
return mListener;
|
||||
}
|
||||
|
||||
bool
|
||||
AudioContext::IsRunning() const
|
||||
{
|
||||
return mAudioContextState == AudioContextState::Running;
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
AudioContext::DecodeAudioData(const ArrayBuffer& aBuffer,
|
||||
const Optional<OwningNonNull<DecodeSuccessCallback> >& aSuccessCallback,
|
||||
|
|
|
@ -181,6 +181,7 @@ public:
|
|||
AudioListener* Listener();
|
||||
|
||||
AudioContextState State() const { return mAudioContextState; }
|
||||
bool IsRunning() const;
|
||||
|
||||
// Those three methods return a promise to content, that is resolved when an
|
||||
// (possibly long) operation is completed on the MSG (and possibly other)
|
||||
|
|
Загрузка…
Ссылка в новой задаче