媒体流(MediaStream)

MediaStream 接口是一个媒体内容的流.。一个流包含几个轨道,比如视频和音频轨道。

属性

MediaStream.active 只读
布尔型。如果这个流处于活动状态值为true,反之为false
MediaStream.ended 只读
布尔型。如果 ended 事件在这个对象上触发了,也就是说这个流已经被完全读取,值为true。 如果还没有到达这个流的尾部,值为false。
MediaStream.id 只读
这是一个包含36个字符的 DOMString ,用来作为这个对象的唯一标识符 (GUID) 。

事件处理

MediaStream.onaddtrack
这是addtrack事件在这个对象上触发时调用的事件处理器[EventHandler],这时一个MediaStreamTrack对象被添加到这个流。
MediaStream.onended
这是当流终止[ended]时触发的事件。
MediaStream.onremovetrack
这是removetrack事件在这个对象上触发事调用的事件处理器[EventHandler],这时一个对象从流上移除。

方法

MediaStream.addTrack()
存储传入参数 MediaStreamTrack 的一个副本。如果这个轨道已经被添加到了这个媒体流,什么也不会发生; 如果目标轨道为“完成”状态(也就是已经到尾部了),一个INVALID_STATE_RAISE异常会产生。
MediaStream.clone()
返回这个MediaStream对象的克隆版本。返回的版本会有一个新的ID。
返回给定ID的轨道。如果没有参数或者没有指定ID的轨道,将返回null。如果有几个轨道有同一个ID,将返回第一个。
MediaStream.getTracks()
返回流中所有的MediaStreamTrack列表。
MediaStream.getAudioTracks()
返回流中kind属性为"audio"的MediaStreamTrack列表。顺序是不确定的,不同浏览器间会有不同,每次调用也有可能不同。
MediaStream.getTrackById()
返回给定ID的轨道。如果没有参数或者没有指定ID的轨道,将返回null。如果有几个轨道有同一个ID,将返回第一个。
MediaStream.getVideoTracks()
返回流中kind属性为"video"的MediaStreamTrack列表。顺序是不确定的,不同浏览器间会有不同,每次调用也有可能不同。
MediaStream.removeTrack()
移除作为参数传入的 MediaStreamTrack。 如果这个轨道不在MediaStream对象中什么也不会发生; 如果目标轨道为“完成”状态,一个INVALID_STATE_RAISE异常会产生。

说明

说明 状态 评论
Media Capture and Streams
MediaStream
Candidate Recommendation

浏览器支持情况

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
MediaStreamChrome Full support 55
Full support 55
Full support 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 12Firefox Full support 15IE No support NoOpera Full support 42
Full support 42
Full support 15
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari Full support 11WebView Android Full support 55
Full support 55
Full support ≤37
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android Full support 55
Full support 55
Full support 25
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android Full support 15Opera Android Full support 42
Full support 42
Full support 14
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS Full support 11Samsung Internet Android Full support 6.0
Full support 6.0
Full support 1.5
Prefixed
Prefixed Implemented with the vendor prefix: webkit
MediaStream() constructorChrome Full support 21Edge Full support ≤18Firefox Full support 44IE No support NoOpera Full support 42Safari No support NoWebView Android Full support 37Chrome Android Full support 25Firefox Android Full support 42Opera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 6.0
activeChrome Full support 45Edge Full support 12Firefox Full support 52IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 45Chrome Android Full support 45Firefox Android Full support 52Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 5.0
active eventChrome Full support 45Edge Full support ≤79Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android Full support 5.0
addTrackChrome Full support 26Edge Full support 12Firefox Full support 44IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5
addtrack eventChrome Full support YesEdge Full support 12Firefox Full support 50IE No support NoOpera No support NoSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 50Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
cloneChrome Full support 45Edge Full support 12Firefox Full support 48IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 45Chrome Android Full support 45Firefox Android Full support 48Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 5.0
ended
Deprecated
Chrome No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 52.
Edge ? Firefox No support NoIE No support NoOpera No support ? — 39Safari ? WebView Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 52.
Chrome Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 52.
Firefox Android No support NoOpera Android No support ? — 41Safari iOS ? Samsung Internet Android No support ? — 6.0
Notes
No support ? — 6.0
Notes
Notes Deprecated in Samsung Internet 6.0.
getAudioTracksChrome Full support 26Edge Full support 12Firefox Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5
getTrackByIdChrome Full support 26Edge Full support 12Firefox Full support 49IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android Full support 49Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5
getTracks
Experimental
Chrome Full support 45Edge Full support 12Firefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 45Chrome Android Full support 45Firefox Android Full support YesOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 5.0
getVideoTracks
Experimental
Chrome Full support 26Edge Full support 12Firefox Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5
idChrome No support ? — 54Edge No support 12 — 79Firefox Full support 41IE No support NoOpera No support ? — 39Safari Full support YesWebView Android No support ? — 54Chrome Android No support ? — 54Firefox Android Full support 41Opera Android No support ? — 41Safari iOS Full support YesSamsung Internet Android No support ? — 6.0
inactive eventChrome Full support 45Edge Full support ≤79Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android Full support 5.0
label
Deprecated
Chrome No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 45.
Edge ? Firefox ? IE No support NoOpera No support NoSafari ? WebView Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 45.
Chrome Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 45.
Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android No support ? — 6.0
Notes
No support ? — 6.0
Notes
Notes Deprecated in Samsung Internet 5.0.
onactiveChrome Full support 45Edge Full support ≤79Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android Full support 5.0
onaddtrackChrome Full support 26Edge Full support 12Firefox Full support 50IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android Full support 50Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5
oninactiveChrome Full support 45Edge Full support ≤79Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android Full support 5.0
onremovetrackChrome Full support 26Edge Full support 12Firefox No support NoIE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5
removeTrackChrome Full support 26Edge Full support 12Firefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android Full support YesOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5
removetrack eventChrome Full support YesEdge Full support 12Firefox No support NoIE No support NoOpera No support NoSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
stop
Deprecated
Chrome No support ? — 47Edge No support 13 — 79Firefox ? IE No support NoOpera No support NoSafari ? WebView Android No support ? — 47Chrome Android No support ? — 47Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android No support ? — 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

相关内容

  • Using the MediaStream API