--- title: OscillatorNode.stop() slug: Web/API/OscillatorNode/stop translation_of: Web/API/OscillatorNode/stop ---
{{ APIRef("Web Audio API") }}
这个 stop
方法 {{ domxref("OscillatorNode") }} 接口在指定时间内停止播放,它的参数是可选的,默认情况下是0.
oscillator.stop(when); // stop playing oscillator at when
0
. If the time is equal to or before the current audio context time, the oscillator will stop playing immediately.下面的示例显示一个基本用法{{ domxref("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 |
---|---|---|
{{SpecName('Web Audio API', '#widl-OscillatorNode-stop-void-double-when', 'stop')}} | {{Spec2('Web Audio API')}} |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 14 {{property_prefix("webkit")}} | {{CompatVersionUnknown}} | 23 [1] | {{CompatNo}} | 15 {{property_prefix("webkit")}} 22 (unprefixed) |
6 {{property_prefix("webkit")}} |
Feature | Android | Chrome | Edge | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatVersionUnknown}} | 28 {{property_prefix("webkit")}} | 25 [1] | 1.2 | {{CompatNo}} | {{CompatNo}} | 6 {{property_prefix("webkit")}} |
[1] The parameter wasn't optional until Firefox 30.