OscillatorNode.stop()

这个 stop方法 OscillatorNode 接口在指定时间内停止播放,它的参数是可选的,默认情况下是0.

语法

oscillator.stop(when); // stop playing oscillator at when

参数

when
An optional double representing the audio context time when the oscillator should stop. If a value is not included, it defaults to 0. If the time is equal to or before the current audio context time, the oscillator will stop playing immediately.

例如

下面的示例显示一个基本用法AudioContext创建子节点。一个应用的例子,看看我们的演示( Violent Theremin demo (see app.js for relevant code).

// create web audio api context
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// create Oscillator node
var oscillator = audioCtx.createOscillator();
oscillator.connect(audioCtx.destination);
oscillator.start();
oscillator.stop(audioCtx.currentTime + 2); // stop 2 seconds after the current time

规定

Specification Status Comment
Web Audio API
stop
Working Draft  

浏览器的兼容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 14 webkit (Yes) 23 [1] 未实现 15 webkit
22 (unprefixed)
6 webkit
Feature Android Chrome Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support 未实现 (Yes) 28 webkit 25 [1] 1.2 未实现 未实现 webkit

[1] The parameter wasn't optional until Firefox 30.

See also

文档标签和贡献者