通过 canvas 在 antmedia 直播中嵌入徽标
Embed logo in antmedia live stream via canvas
正在关注 https://antmedia.io/how-to-merge-live-stream-and-canvas-in-webrtc-easily/ 上的博客,该博客解释了如何在 antmedia 直播中嵌入徽标。但是,我不太明白如何使用 javascript SDK 初始化 localStream,如博客中所示。具体来说,initWebRTCAdaptor()的实现在哪里:
//initialize the webRTCAdaptor with the localStream created.
//initWebRTCAdaptor method is implemented below
initWebRTCAdaptor(localStream);
一个完整的工作示例会很有帮助。
博客 post 似乎不是最新的。
让我分享一下如何才能拥有此功能。
只需在 WebRTCAdaptor
构造函数中添加一个 localStream
参数即可。
其次,使用下面的代码代替 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);
});
正在关注 https://antmedia.io/how-to-merge-live-stream-and-canvas-in-webrtc-easily/ 上的博客,该博客解释了如何在 antmedia 直播中嵌入徽标。但是,我不太明白如何使用 javascript SDK 初始化 localStream,如博客中所示。具体来说,initWebRTCAdaptor()的实现在哪里:
//initialize the webRTCAdaptor with the localStream created.
//initWebRTCAdaptor method is implemented below
initWebRTCAdaptor(localStream);
一个完整的工作示例会很有帮助。
博客 post 似乎不是最新的。 让我分享一下如何才能拥有此功能。
只需在 WebRTCAdaptor
构造函数中添加一个 localStream
参数即可。
其次,使用下面的代码代替 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);
});