最近又時間學習了一下視頻流這玩意。多是想到5G來臨,再加上WebRTC這玩意的出現,之後H5Game的IM系統將不限於單純的文本了。故此,研究了一番,僅做拋磚引玉。ide
① , 使用HTML5標籤<video>來播放視頻
以下:學習
<video autoplay playsinline id="videoPlayer"></video>
a,autoplay : 自動播放
b,playsinline : 使用本標籤播放(不使用第三方)
② ,獲取video標籤this
private _videoPlayer : any = null; this._videoPlayer = document.querySelector("video#videoPlayer");
③,使用navigator.mediaDevices.getUserMedia得到媒體流3d
private init2RTC : Function = () : void => { if( !navigator.mediaDevices || !navigator.mediaDevices.getUserMedia ){ console.log(`getUserMedia is not supported!`); }else{ this._videoPlayer = document.querySelector("video#videoPlayer"); const $constraints : Object = { video : true, audio : true }; navigator.mediaDevices.getUserMedia($constraints) .then(this.gotMediaStream.bind(this)) .catch( this.gotMediaError.bind(this) ); } }; private gotMediaStream : Function = ( stream : MediaStream ) : void => { this._videoPlayer.srcObject = stream; }; private gotMediaError : Function = ( error : any ) : void => { console.log(`mediastream error : ${error}`); };