AudioContext.suspend() - Web API 接口参考 编辑
AudioContext
接口的suspend()
方法暂停音频上下文对象中的进度,并暂时剥离进程对音频设备硬件的访问权限, 减少CPU和电池的使用。 当程序在一段时间内不会使用音频上下文对象时,这个方法对减少硬件资源占用是非常有用的。
若对OfflineAudioContext
调用此方法,将会抛出 INVALID_STATE_ERR
错误。
Syntax
var audioCtx = new AudioContext();
audioCtx.suspend().then(function() { ... });
Returns
A Promise
that resolves with void. The promise is rejected if the context has already been closed.
Example
The following snippet is taken from our AudioContext states demo (see it running live.) When the suspend/resume button is clicked, the AudioContext.state
is queried — if it is running
, suspend()
is called; if it is suspended
, resume
is called. In each case, the text label of the button is updated as appropriate once the promise resolves.
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';
});
}
}
Specifications
Specification | Status | Comment |
---|---|---|
Web Audio API close() | Working Draft |
Browser compatibility
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 41.0 | 40.0 (40.0) | 未实现 | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? | ? | 41.0 |
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论