Selaa lähdekoodia

Merge pull request #17499 from Mugen87/dev38

Audio: Add .setMediaStreamSource().
Mr.doob 5 vuotta sitten
vanhempi
commit
8b5a537813
3 muutettua tiedostoa jossa 18 lisäystä ja 1 poistoa
  1. 5 0
      docs/api/en/audio/Audio.html
  2. 2 1
      src/audio/Audio.d.ts
  3. 11 0
      src/audio/Audio.js

+ 5 - 0
docs/api/en/audio/Audio.html

@@ -192,7 +192,12 @@
 		<p>
 		Applies the given object of type [link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement HTMLMediaElement] as the source of this audio.<br />
 		Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
+		</p>
 
+		<h3>[method:Audio setMediaStreamSource]( mediaStream )</h3>
+		<p>
+		Applies the given object of type [link:https://developer.mozilla.org/en-US/docs/Web/API/MediaStream MediaStream] as the source of this audio.<br />
+		Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
 		</p>
 
 		<h3>[method:Audio setNodeSource]( audioNode )</h3>

+ 2 - 1
src/audio/Audio.d.ts

@@ -27,7 +27,8 @@ export class Audio extends Object3D {
 
 	getOutput(): GainNode;
 	setNodeSource( audioNode: AudioBufferSourceNode ): this;
-	setMediaElementSource( mediaElement: MediaElementAudioSourceNode ): this;
+	setMediaElementSource( mediaElement: HTMLMediaElement ): this;
+	setMediaStreamSource( mediaStream: MediaStream ): this;
 	setBuffer( audioBuffer: AudioBuffer ): this;
 	play(): this;
 	onEnded(): void;

+ 11 - 0
src/audio/Audio.js

@@ -66,6 +66,17 @@ Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	},
 
+	setMediaStreamSource: function ( mediaStream ) {
+
+		this.hasPlaybackControl = false;
+		this.sourceType = 'mediaStreamNode';
+		this.source = this.context.createMediaStreamSource( mediaStream );
+		this.connect();
+
+		return this;
+
+	},
+
 	setBuffer: function ( audioBuffer ) {
 
 		this.buffer = audioBuffer;