我正在关注 https://antmedia.io/how-to-merge-live-stream-and-canvas-in-webrtc-easily/ 上的博客这解释了如何在 antmedia 直播中嵌入 Logo 。但是,我不太清楚如何使用 javascript SDK 初始化 localStream,如博客中所示。具体来说,initWebRTCAdaptor()的实现在哪里:
//initialize the webRTCAdaptor with the localStream created.
//initWebRTCAdaptor method is implemented below
initWebRTCAdaptor(localStream);
一个完整的工作样本将非常有帮助。
最佳答案
博客文章似乎不是最新的。
让我分享如何拥有此功能。
只需添加 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);
});
关于html5-canvas - 通过 Canvas 在 antmedia 直播中嵌入 logo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62789768/