how to add a audio stream on canvas stream in webrtc

后端 未结 1 1759
情书的邮戳
情书的邮戳 2021-01-23 01:14

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 () doe

相关标签:
1条回答
  • 2021-01-23 02:12

    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);
    
    0 讨论(0)
提交回复
热议问题