Baseline Widely available
The stop()
method of the MediaStreamTrack
interface stops the track.
None.
Return valueNone (undefined
).
Calling stop()
tells the user agent that the track's sourceâwhatever that source may be, including files, network streams, or a local camera or microphoneâis no longer needed by the MediaStreamTrack
. Since multiple tracks may use the same source (for example, if two tabs are using the device's microphone), the source itself isn't necessarily immediately stopped. It is instead disassociated from the track and the track object is stopped. Once no media tracks are using the source, the source may actually be completely stopped.
Immediately after calling stop()
, the readyState
property is set to ended
. Note that the ended
event will not be fired in this situation.
In this example, we see a function which stops a streamed video by calling stop()
on every track on a given <video>
.
function stopStreamedVideo(videoElem) {
const stream = videoElem.srcObject;
const tracks = stream.getTracks();
tracks.forEach((track) => {
track.stop();
});
videoElem.srcObject = null;
}
This works by obtaining the video element's stream from its srcObject
property. Then the stream's track list is obtained by calling its getTracks()
method. From there, all that remains to do is to iterate over the track list using forEach()
and calling each track's stop()
method.
Finally, srcObject
is set to null
to sever the link to the MediaStream
object so it can be released.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3