HTML AudioContext createMediaStreamTrackSource() Method
Last Updated :
24 Apr, 2023
Prerequisite: AudioContext baseLatency Property
The HTML AudioContext.createMediaStreamTrackSource() is used to create an instance of MediaStreamAudioSourceNode object which can be used by the user to manipulate the stream feed in the
AudioContext.createMediaStreamTrackSource() method. The MediaStreamAudioSourceNode is used in audio processing graph for use and manipulation.
Syntax:
audioSourceNode = audioContext.createMediaStreamSource(stream)
Parameter: This method accepts single parameter stream that holds the mediaStream(stream) to serve as an audio source.
Return Value: This method returns the MediaStreamAudioSourceNode object.
Example:
html
<!DOCTYPE html>
< html >
< body style = "text-align:center;" >
< center >
< h1 style = "color:green" >
GeeksforGeeks
</ h1 >
< h2 >AudioContext.createMediaStreamSource() Method</ h2 >
< script >
navigator.mediaDevices.getUserMedia(
{ audio: true, video: true })
.then(function (stream) {
video.srcObject = stream;
// Create a MediaStreamAudioSourceNode
// Feed the HTMLMediaElement into it
var audioCtx = new AudioContext();
var source = audioCtx
.createMediaStreamSource(stream);
if (source)
console.log('Geeks For Geeks is On');
})
.catch(function (err) {
console.log('Error occured: ' + err);
});
</ script >
</ center >
</ body >
</ html >
|
Output:
When some Error Occurs
Explanation: In this example, we grab a media (audio + video) stream from navigator.getUserMedia, feed the media into a video element to play then mute the audio, but then also feed the audio into a MediaStreamAudioSourceNode.
Supported Browsers:
- Google Chrome
- Microsoft Edge
- Firefox
- Opera
- Safari
Share your thoughts in the comments
Please Login to comment...