webrtc学习——mediaStream和MediaStreamTrack

This is an experimental technology
Because this technology‘s specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

The MediaStream interface represents a stream of media content. A stream consists of several tracks, like video or audio tracks.

Attributes

MediaStream.ended Read only
Is a Boolean value with a value of true if the ended event has been fired on the object, meaning that the stream has been completely read, or false if the end of hte stream has not been reached.
MediaStream.id Read only
Is a DOMString containing 36 characters denoting a unique identifier (GUID) for the object.

Event handlers

MediaStream.onaddtrack
Is a EventHandler containing the action to perform when an addtrack event is fired on the object, that is when a new MediaStreamTrack object is added.
MediaStream.onended
Is a EventHandler containing the action to perform when an ended event is fired on the object, that is when the streaming is terminating.
MediaStream.onremovetrack
Is a EventHandler containing the action to perform when an removetrack event is fired on the object, that is when a  MediaStreamTrack object is removed from it.

Methods

MediaStream.addTrack()
Stores a copy of the MediaStreamTrack given as argument. If the track has already been added to the MediaStream object, nothing happens; if the track is in the finished state, that is has already reached its end, the exception INVALID_STATE_RAISE is raised.
MediaStream.clone()
Return a clone of the MediaStream objet. The clone will have a new id value.
Returns the track whose id corresponds to the one given in parameters, trackid. If no parameter is given, or if no track with that id does exists, it returns null. If several tracks have the same id, it returns the first one.
MediaStream.getAudioTracks()
Returns a list of the MediaStreamTrack stored in the MediaStream object that have their kind attribute set to "audio". The order is not defined, and may vary from one browser to an other, but also from one call to the method to another.
MediaStream.getTrackById()
Returns the track whose id corresponds to the one given in parameters, trackid. If no parameter is given, or if no track with that id does exists, it returns null. If several tracks have the same id, it returns the first one.
MediaStream.getVideoTracks()
Returns a list of the MediaStreamTrack stored in the MediaStream object that have their kind attribute set to "video". The order is not defined, and may vary from one browser to an other, but also from one call to the method to another.
MediaStream.removeTrack()
Removes the MediaStreamTrack given as argument. If the track is not part of the MediaStream object, nothing happens; if the track is in the finished state, that is has already reached its end, the exception INVALID_STATE_RAISE is raised.

MediaStreamTrack

Summary

The MediaStream interface represents a stream of media content. A stream consists of several tracks, like video or audio tracks.

Properties

MediaStreamTrack.enabled
Is a Boolean value with a value of true if the track is enabled, that is allowed to render the media source stream; or false if it is disabled, that is not rendering the media source stream but silence and blackness. If the track has been disconnected, this value can be changed but has no more effect.
MediaStreamTrack.id Read only
Returns a DOMString containing a unique identifier (GUID) for the track; it is generated by the browser.
MediaStreamTrack.kind Read only
Returns a DOMString set to "audio" if the track is an audio track and to "video", if it is a video track. It doesn‘t change if the track is deassociated from its source.
MediaStreamTrack.label Read only
Returns a DOMString containing a user agent-assigned label that identifies the track source, as in"internal microphone". The string may be left empty and is empty as long as no source has been connected. When the track is deassociated from its source, the label is not changed.
MediaStreamTrack.muted Read only
Returns a Boolean value with a value of true if the track is muted, false otherwise.
MediaStreamTrack.readonly Read only
Returns a Boolean value with a value of true if the track is readonly (such a video file source or a camera that settings can‘t be modified),false otherwise.
MediaStreamTrack.readyState Read only
Returns an enumerated value giving the status of the track.It takes one of the following values:

  • "live" which indicates that an input is connected and does its best-effort in providing real-time data. In that case, the output of data can be switched on or off using theMediaStreamTrack.enabled attribute.
  • "ended" which indicates that the input is not giving any more data and will never provide new data.
MediaStreamTrack.remote Read only
Returns a boolean value with a value of true if the track is sourced by a RTCPeerConnectionfalseotherwise.

Event handlers

MediaStreamTrack.onstarted
Is a EventHandler containing the action to perform when an started event is fired on the object, that is when a new MediaStreamTrack object is added.
MediaStreamTrack.onmute
Is a EventHandler containing the action to perform when an mute event is fired on the object, that is when the streaming is terminating.
MediaStreamTrack.onunmute
Is a EventHandler containing the action to perform when an unmute event is fired on the object, that is when a  MediaStreamTrack object is removed from it.
MediaStreamTrack.onoverconstrained
Is a EventHandler containing the action to perform when an overconstrained event is fired on the object, that is when a  MediaStreamTrack object is removed from it.
MediaStreamTrack.oneended
Is a EventHandler containing the action to perform when an ended event is fired on the object, that is when a  MediaStreamTrack object is removed from it.

Methods

MediaStreamTrack.getConstraints()
 
MediaStreamTrack.applyConstraints()
 
MediaStreamTrack.getSettings()
 
MediaStreamTrack.getCapabilities()
 
MediaStreamTrack.clone()
 
MediaStreamTrack.stop()
Stops playing the source associated to the track, both the source and the track are deassociated. The track state is set to ended.

Specifications

Specification Status Comment
Media Capture and Streams
The definition of ‘MediaStreamTrack‘ in that specification.
Candidate Recommendation Initial definition

https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack

https://developer.mozilla.org/en-US/docs/Web/API/MediaStream

时间: 2024-11-08 20:25:49

webrtc学习——mediaStream和MediaStreamTrack的相关文章

WebRTC学习笔记_Demo收集

1.     WebRTC学习 1.1   WebRTC现状 本人最早接触WebRTC是在2011年底,那时Google已经在Android源代码中添?了webrtc源代码,放在/external/webrtc/,可是Android并没实用到它,更没有被浏览器使用.当时试图在Android 2.3(Gingerbread)高通平台的手机上用H.264 硬件codec替换掉WebRTC缺省使用的VP8软codec,费了不少劲勉强换掉后效果非常差仅仅得放弃. 近期得知Google最新版的Chrome

WebRTC学习之九:摄像头的捕捉和显示

较新的WebRTC源码中已经没有了与VoiceEngine结构对应的VidoeEngine了,取而代之的是MeidaEngine.MediaEngine包含了MediaEngineInterface接口及其实现CompositeMediaEngine,CompositeMediaEngine本身也是个模板类,两个模板参数分别是音频引擎和视频引擎.CompositeMediaEngine派生类WebRtcMediaEngine依赖的模板参数是WebRtcVoiceEngine和WebRtcVide

webrtc学习——RTCPeerConnection

The RTCPeerConnection interface represents a WebRTC connection and handles efficient streaming of data between two peers. Warning: RTCPeerConnection and RTCSessionDescription are currently prefixed in most browsers. You should include a polyfill if y

webrtc学习(一): webrtc开始

一. 编译webrtc 1. 预先准备 1)  vpn. 用于同步代码. 这里给一个大概的估计吧. windows端包含vs2013 win8sdk wdk chromium源码等等, 总共需要至少8G. android端还需要android ndk sdk以及大量的依赖库, 大致也是10G往上. 所以需要网速不好的话, 同步一天也是很正常. 2. 同步代码及编译 http://www.webrtc.org/reference/getting-started 参考这个链接, 很详细, 需要认真看

webrtc学习: 部署stun和turn服务器

webrtc的P2P穿透部分是由libjingle实现的. 步骤顺序大概是这样的: 1. 尝试直连. 2. 通过stun服务器进行穿透 3. 无法穿透则通过turn服务器中转. stun 服务器比较简单. 网上也有很多公开的stun服务器可以用于测试. 例如 stun.ideasip.com 这里需要注意一下. 我在做android应用时. 在少数老旧的手机上出现过一个bug: PeerConnection close时非常慢. 大概需要50~80s. 后来反复检查, 才发现问题出在公用的stu

webrtc学习(二): audio_device之opensles

audio_device是webrtc的音频设备模块.  封装了各个平台的音频设备相关的代码 audio device 在android下封装了两套音频代码. 1. 通过jni调用java的media进行操作. 2. 直接通过opensl es的native c接口进行操作. native 接口自然比较高效,  但缺点在于opensl 要求 android 2.3+. OpenSL ES (Open Sound Library for Embedded Systems) 是无授权费.跨平台.针对

webrtc 学习资源1

1,http://www.webrtc.org/  webrtc官网,神马编译,神马下载,这里的解决方案才是最权威的. --------------------------------- 2,https://code.google.com/p/webrtc/  webrtc源码下载地点,您还可以随时随地关注最新修改. ---------------------------------- 3,https://webrtchacks.com/ 里面都是分享webrtc相关技术的文章 --------

webrtc学习———记录一

最近导师让研究一下webrtc,希望将来用到我们的ICT2系统中. 但是从来没有过做web的基础,无论前端还是后端,html.js全都从头学起.html还好说,没有太过复杂的东西. js就有点难度了,大致翻了一下js权威指南的书,了解了一下基本的语法,也算足够应付.但是对其中浏览器内置的各种对象,完全不了解. 只能慢慢熟悉,一步一步来. 第一部分 获取webcamera 这个比较简单,主要使用了getUserMedia()这个函数.下面是从网上获取的资料: 1.navigator.getUser

webrtc学习笔记1(建立连接基本流程)

最近在做一个基于webrtc的视频软件,以下是自己对于上层建立通话连接流程的基本理解,记录于此. 假设A和B要建立视频通话,A为房间创建端,B为加入房间端: 1.A通过http登录.获取其他服务器地址(做一些保存用户信息的操作,获取信令.stun.turn服务器地址等,非必要) 2.A和信令服务器建立websocket长连接 3.A通过websocket向信令服务器注册(创建房间,记录房间号,等待B加入房间) 4.A创建本地视频,获取A的sdp信息 5.B创建本地视频,获取B的sdp信息 6.B