0

这是我用来翻转相机的方法。

function flipCameraMethod() {
    setFlipClicked(!flipClicked);
    setFacingVariable(flipClicked?"environment":"user");
    userVideo.current.srcObject.getTracks().forEach(function (track) {
        track.stop();
    });
    userVideo.current.srcObject=null;
    console.log('userVideo.current.srcObject.getTracks()',userVideo.current.srcObject);
    var oldTrack = stream.getTracks();
    console.log('oldTrack', oldTrack);
    navigator.mediaDevices.getUserMedia({ video: { facingMode: facingVariable, deviceId: {
        exact: window.selectedCamera
      } }, audio: true }).then(NewStream => {
        setStream(NewStream);
        mypeer.current.removeTrack(stream.getVideoTracks()[0],stream);
        mypeer.current.addTrack(NewStream.getVideoTracks()[0],stream);
        userVideo.current.srcObject=NewStream;

console.log('userVideo.current.srcObject.getTracks()',userVideo.current.srcObject.getTracks()); }); }enter code here

4

0 回答 0