AudioContext
的 resume()
方法,恢复之前暂停播放的音频。
如果在OfflineAudioContext
上调用,会导致INVALID_STATE_ERR错误。
语法
var audioCtx = new AudioContext();
audioCtx.resume().then(function() { ... });
结果
Promise
成功的话返回空值,返回失败是因为context已经关闭了。
示例
下面的代码是 AudioContext states demo (see it running live)的一部分。当点击暂停/恢复按钮的时候,需要AudioContext.state
做判断:如果是运行状态,调用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';
});
}
}
规范
Specification | Status | Comment |
---|---|---|
Web Audio API close() |
Working Draft |
兼容性
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 |