Просмотр исходного кода

Audio: stop audio with a delay (#29376)

* 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>
Rostislav Harlanov 1 год назад
Родитель
Сommit
43dcbc1aca
2 измененных файлов с 5 добавлено и 3 удалено
  1. 3 1
      docs/api/en/audio/Audio.html
  2. 2 2
      src/audio/Audio.js

+ 3 - 1
docs/api/en/audio/Audio.html

@@ -164,6 +164,7 @@
 
 		<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>
@@ -244,8 +245,9 @@
 		<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>

+ 2 - 2
src/audio/Audio.js

@@ -158,7 +158,7 @@ class Audio extends Object3D {
 
 	}
 
-	stop() {
+	stop( delay = 0 ) {
 
 		if ( this.hasPlaybackControl === false ) {
 
@@ -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;
 
 		}

粤ICP备19079148号