MediaStreamTrack.stop()
method stops the track.
track.stop()
调用
stop()
tells the
用户代理
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()
,
readyState
property is set to
ended
.
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(function(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()
方法。
最后,
srcObject
被设为
null
to sever the link to the
MediaStream
object so it can be released.
| 规范 | 状态 | 注释 |
|---|---|---|
|
媒体捕获和流
The definition of 'MediaStreamTrack.stop()' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
stop
|
Chrome 61 | Edge 12 | Firefox 34 | IE No | Opera 45 | Safari Yes | WebView Android 61 | Chrome Android 61 | Firefox Android 34 | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 8.0 |
完整支持
不支持
MediaStreamTrack
, the interface it belongs to.
MediaStreamTrack.readyState
ended
MediaStreamTrack
AudioStreamTrack
BlobEvent
CanvasCaptureMediaStream
ConstrainBoolean
ConstrainDOMString
ConstrainDouble
ConstrainLong
DoubleRange
HTMLCanvasElement.captureStream()
LongRange
MediaDevices
MediaStream
MediaStreamTrackEvent
MediaTrackCapabilities
MediaTrackConstraints
MediaTrackSettings
MediaTrackSupportedConstraints
Navigator.mediaDevices
NavigatorUserMedia
NavigatorUserMediaError
VideoStreamTrack
navigator.mediaDevices.getUserMedia()