webrtc와 함께 ionic 2를 사용하여 전면 및 후면 카메라에서 비디오 스트림을 가져옵니다.
아래 내 typescript 코드를 참조하십시오.
if (this.isFrontCam) {
constraints = {
mandatory: {},
optional: [{sourceId: this.cameras[0]}]
};
} else {
constraints = {
mandatory: {},
optional: [{sourceId: this.cameras[1]}]
};
}
if (this.currentVideoStream && this.currentVideoStream !=null) {
this.currentVideoStream.getTracks().forEach(function (track) {
track.stop();
});
this.currentVideoStream.release();
this.currentVideoStream = null;
}
var n = <any>navigator;
n.getUserMedia = n.getUserMedia || n.webkitGetUserMedia || n.mozGetUserMedia || n.msGetUserMedia;
//getting local video stream
n.getUserMedia({
audio: true,
video: constraints
}, function (myStream) {
alert("Current Video stream " + self.currentVideoStream);
self.currentVideoStream = myStream;
alert("New Stream"+ myStream);
//displaying local video stream on the page
(<HTMLVideoElement>document.getElementById('localVideo')).src = window.URL.createObjectURL(myStream);
두 개의 다른 (전면 및 후면) 카메라 장치 ID ( this.cameras
)를 얻고 있으며 개별적으로 사용하면 두 카메라가 모두 예상대로 작동하지만 위의 코드 (UI에서 버튼 클릭이이 기능을 호출 함)를 사용하여 뒤집 으면 위와 같이 표시되지 않습니다. 일. 단순히 검은 화면 만 표시됩니다.
아래 두 줄을 제거하여이 문제를 해결할 수있었습니다.
this.currentVideoStream.release();
this.currentVideoStream = null;
및 추가 (<HTMLVideoElement>document.getElementById('localVideo')).play();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다