本文介绍了如何在 webrtc 的画布流上添加音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将通过 getusermedia() 获取的音频流添加到画布流中,并将其发送到远程对等方...于是抬头一看,竟然有addTrack().但是addTrack() 似乎不能正常工作.我在 Chrome 上运行.
I want to add an audio stream obtained via getusermedia () to the canvas stream and send it to the remote peer...So I looked up, and there was addTrack ().But addTrack () does not seem to work properly. I am running on chrome.
var audioTracks;
navigator.getUserMedia({ "audio": true, "video": false }, function (stream)
{
audioTracks = stream.getAudioTracks()[0];
}, function(error) { console.log(error);});
.
.
.
var sharestream = canvas2.captureStream(25); // 25 FPS
peerConn.addTrack(audioTracks,sharestream);
peerConn.addStream(sharestream);
这是我代码的一部分.怎么了?我的 webrtc 完整源代码工作正常,但它不适用于 addTrack().
It's part of my code. What's wrong?My webrtc full source code works fine, but it does not work with addTrack ().
推荐答案
于 10-29-2018 更新以将 getAudioTracks
替换为 getTracks
:
Updated on 10-29-2018 to replace getAudioTracks
with getTracks
:
var canvasStream = canvas2d.captureStream(25); // parameter is optional
// get first audio track
// var audioTrack = audioStream.getAudioTracks()[0];
var audioTrack = audioStream.getTracks().filter(function(track) {
return track.kind === 'audio'
})[0];
// append audio track into Canvas2D stream
canvasStream.addTrack( audioTrack );
// now canvas2D stream has both audio and video tracks
// peerConnection.addStream( canvasStream );
canvasStream.getTracks().forEach(function(track) {
peerConnection.Track( track, canvasStream );
});
// create offer or answer descriptions
peerConnection.createOffer(hints).then(success).catch(failure);
这篇关于如何在 webrtc 的画布流上添加音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!