MediaStream API

您正在阅读此内容的英文版本,因为该语系尚未翻译。 帮助我们翻译此文章吧!

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

媒体流处理API(通常被称为媒体流API或流API)是描述音频或视频数据流的 WebRTC 的一部分,处理它们的方法,与数据类型相关的约束,成功和错误 当异步使用数据时的回调以及在处理期间触发的事件。

基本概念

这个API是基于操纵一个 MediaStream 对象代表音频或视频相关数据的流量。 通常一个 MediaStream是作为一个简单的URL string 它可以用来引用存储在DOM中的数据 File, 或者一个 Blob 对象建立 window.URL.createObjectURL(), 如视频所描述的

一个 MediaStream 包含零个或更多的 MediaStreamTrack 对象,代表着各种的声轨和视频轨。 每一个 MediaStreamTrack 可能有一个或更多的通道。这个通道代表着媒体流的最小单元,比如一个音频信号对应着一个对应的扬声器,像是在立体声音轨中的左通道或右通道。

MediaStream 对象有着单一的输入和输出。由 getUserMedia() 创建的 MediaStream 对象是在本地借助用户相机和麦克风的源输入。非本地的 MediaStream 代表了一个媒体元素, 像是<video> 元素或是 <audio>元素, 一般是源自网络的流,并通过 WebRTC PeerConnection API 或使用 Web Audio API 获得MediaStreamAudioSourceNode 元素。MediaStream 对象的输出能链接到一个用户。 它可以是一个媒体元素, 像是 <audio> 或者 <video>, the WebRTC PeerConnection API 或是 Web Audio API MediaStreamAudioDestinationNode

参考

在这些参考文章中,您将找到构成Media Capture和Streams API的每个接口和事件需要了解的基本信息。

 

浏览器支持

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
MediaStreamChrome Full support 14Edge Full support YesFirefox Full support 15IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 18Firefox Android Full support 15Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
MediaStream() constructorChrome Full support 19Edge Full support YesFirefox 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 Yes
active eventChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android ?
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 Yes
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 Yes
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 Full support Yes
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 Yes
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 Yes
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 Yes
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 Yes
idChrome No support ? — 54Edge Full support 12Firefox 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 Full support Yes
inactive eventChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android ?
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 Full support Yes
onactiveChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android ?
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 Yes
oninactiveChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android ?
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 Yes
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 Yes
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 Full support 13Firefox ? 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 No

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.
Feature Chrome Firefox (Gecko) Internet Explorer Opera  Safari (WebKit)
Stream API  21webkit  nightly 18moz  ?  12 ? 
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Stream API  未实现  ? ?  未实现  未实现 

当前已经支持在Chrome,欧朋,和Firefox Nightly 18 浏览器使用WenRTC获取相机功能 。在Firefox Nightly 中启用WebRTC 需要你在配置中进行设置:

  • 在地址栏中输入"about:config" ,在需要改变的地方设置为是
  • 找到 "media.navigator.enabled" 的然后设置为true

See Also