博客文章似乎不是最新的。让我分享如何拥有此功能。
只需在构造函数中添加一个localStream
参数WebRTCAdaptor
。其次,使用下面的代码代替initWebRTCAdaptor
有关完整代码,请查看此要点。
https://gist.github.com/mekya/d7d21f78e7ecb2c34d89bd6ec5bf5799
确保在 image.src 中使用自己的图像。(使用本地图像)
var canvas = document.getElementById('canvas');
var vid = document.getElementById('localVideo');
var image=new Image();
image.src="images/play.png";
function draw() {
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
ctx.drawImage(vid, 0, 0, 200, 150);
ctx.drawImage(image,50, 10, 100, 30);
}
}
setInterval(function() { draw(); }, 50);
//capture stream from canvas
var localStream = canvas.captureStream(25);
navigator.mediaDevices.getUserMedia({video: true, audio:true}).then(function (stream) {
var video = document.querySelector('video#localVideo');
video.srcObject = stream;
video.onloadedmetadata = function(e) {
video.play();
};
//initialize the webRTCAdaptor with the localStream created.
//initWebRTCAdaptor method is implemented below
localStream.addTrack(stream.getAudioTracks()[0]);
initWebRTCAdaptor(false, autoRepublishEnabled);
});