From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/audiocontext/resume/index.html | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 files/zh-cn/web/api/audiocontext/resume/index.html (limited to 'files/zh-cn/web/api/audiocontext/resume') diff --git a/files/zh-cn/web/api/audiocontext/resume/index.html b/files/zh-cn/web/api/audiocontext/resume/index.html new file mode 100644 index 0000000000..6491b15d4e --- /dev/null +++ b/files/zh-cn/web/api/audiocontext/resume/index.html @@ -0,0 +1,119 @@ +--- +title: AudioContext.resume() +slug: Web/API/AudioContext/resume +tags: + - AudioContext + - Web Audio API + - resume +translation_of: Web/API/AudioContext/resume +--- +

{{ APIRef("Web Audio API") }}

+ +

{{ domxref("AudioContext") }} 的 resume() 方法,恢复之前暂停播放的音频。

+ +

如果在{{domxref("OfflineAudioContext")}}上调用,会导致INVALID_STATE_ERR错误。

+ +

语法

+ +
var audioCtx = new AudioContext();
+audioCtx.resume().then(function() { ... });
+
+ +

结果

+ +

{{jsxref("Promise")}}成功的话返回空值,返回失败是因为context已经关闭了。

+ +

示例

+ +

下面的代码是 AudioContext states demo (see it running live)的一部分。当点击暂停/恢复按钮的时候,需要{{domxref("AudioContext.state")}}做判断:如果是运行状态,调用{{domxref("suspend()")}},如果是暂停状态,调用resume()。每次点击事件成功后,按钮的文字也会随着变成对应的状态

+ +
susresBtn.onclick = function() {
+  if(audioCtx.state === 'running') {
+    audioCtx.suspend().then(function() {
+      susresBtn.textContent = 'Resume context';
+    });
+  } else if(audioCtx.state === 'suspended') {
+    audioCtx.resume().then(function() {
+      susresBtn.textContent = 'Suspend context';
+    });
+  }
+}
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Web Audio API', '#widl-AudioContext-resume-Promise-void', 'close()')}}{{Spec2('Web Audio API')}} 
+ +

兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(41.0)}}{{CompatGeckoDesktop(40.0)}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari MobileChrome for Android
Basic support{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatChrome(41.0)}}
+
+ +

参见

+ + -- cgit v1.2.3-54-g00ecf