Working with streamed content
Live coding video: working with streamed content
Click on this button to mute or unmute this video or press UP or DOWN buttons to increase or decrease volume level.
Downloads and transcripts
Video
Download video fileTranscripts
Working with streamed content: the MediaSourceElement node
In the previous lesson, we encountered the MediaElementSource node that is used for routing the sound from a <video> or <audio>element stream. The above video shows how to make a simple example step by step, and how to setup FireFox for debugging Web Audio applications and visualize the audio graph.
Typical use:
HTML:
- <audio id=“player” controls crossorigin=“anonymous” loop>
- <source src=“http://mainline.i3s.unice.fr/mooc/guitarRiff1.mp3”>
- Your browser does not support the audio tag.
- </audio>
JavaScript:
- var ctx = window.AudioContext || window.webkitAudioContext;
- var context = new ctx();
- var mediaElement = document.querySelector(‘#player‘);
- var sourceNode = context.createMediaElementSource(mediaElement);
- sourceNode.connect(context.destination); // connect to the speakers
The MediaElementSource node is built using context.createMediaElementSource(elem), where elem is an <audio> or a <video>element.
Then we connect this source Node to other nodes. If we connect it directly to context.destination, the sound goes to the speakers with no additional processing.
In the following lessons, we will see the different nodes that are useful with streamed audio and with the MediaElementSource node. Adding them in the audio graph will enable us to change the sound in many different ways.