Skip to content

Commit

Permalink
Audio: stop audio with a delay (#29376)
Browse files Browse the repository at this point in the history
* feat: audio stop delay parameter

* docs: audio play/stop delay parameter

* Update Audio.html

* fix: do not honor offset

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
  • Loading branch information
tatsmaki and Mugen87 authored Sep 11, 2024
1 parent 4c53075 commit 43dcbc1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/api/en/audio/Audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ <h3>[method:Float getVolume]()</h3>

<h3>[method:this play]( delay )</h3>
<p>
delay (optional) - The delay, in seconds, at which the audio should start playing.<br />
If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts
playback.
</p>
Expand Down Expand Up @@ -244,8 +245,9 @@ <h3>[method:this setPlaybackRate]( [param:Float value] )</h3>
<h3>[method:this setVolume]( [param:Float value] )</h3>
<p>Set the volume.</p>

<h3>[method:this stop]()</h3>
<h3>[method:this stop]( delay )</h3>
<p>
delay (optional) - The delay, in seconds, at which the audio should stop playing.<br />
If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops
playback.
</p>
Expand Down
4 changes: 2 additions & 2 deletions src/audio/Audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Audio extends Object3D {

}

stop() {
stop( delay = 0 ) {

if ( this.hasPlaybackControl === false ) {

Expand All @@ -171,7 +171,7 @@ class Audio extends Object3D {

if ( this.source !== null ) {

this.source.stop();
this.source.stop( this.context.currentTime + delay );
this.source.onended = null;

}
Expand Down

0 comments on commit 43dcbc1

Please sign in to comment.