option.videoTrack/option.audioTrack parameter of the trtc.startLocalVideo() / trtc.startLocalAudio() method.audioTrack and videoTrack:videoElement.captureStream to capture the audio and video being played in the video tag.canvas.captureStream to capture the animation in the canvas.// Check if your current browser supports capturing streams from video elementsif (!HTMLVideoElement.prototype.captureStream) {console.log('your browser does not support capturing stream from video element');return}// Get the video tag that is playing video on your pageconst video = document.getElementByID('your-video-element-ID');// Capture the video stream from the playing videoconst stream = video.captureStream();const audioTrack = stream.getAudioTracks()[0];const videoTrack = stream.getVideoTracks()[0];trtc.startLocalVideo({ option:{ videoTrack } });trtc.startLocalAudio({ option:{ audioTrack } });
// Check if your current browser supports capturing streams from canvas elementsif (!HTMLCanvasElement.prototype.captureStream) {console.log('your browser does not support capturing stream from canvas element');return}// Get your canvas tagconst canvas = document.getElementByID('your-canvas-element-ID');// Capture a 15 fps video stream from the canvasconst fps = 15;const stream = canvas.captureStream(fps);const videoTrack = stream.getVideoTracks()[0];trtc.startLocalVideo({ option:{ videoTrack } });
trtc.startLocalVideo(view) or trtc.startRemoteVideo(view, streamType, userId), you need to pass in the view parameter. The SDK will create a video tag under the specified element tag to play the video.view parameter or pass in null when calling the startLocalVideo or startRemoteVideo method.trtc.getVideoTrack(userId, streamType) method to obtain the corresponding videoTrack.EVENT.VIDEO_PLAY_STATE_CHANGED event will not be triggered. You need to listen to the mute/unmute/ended events of the video track MediaStreamTrack to determine the status of the current video data stream.EVENT.REMOTE_VIDEO_AVAILABLE and EVENT.REMOTE_VIDEO_UNAVAILABLE events to handle the lifecycle of remote video.await trtc.startLocalVideo();const videoTrack = trtc.getVideoTrack();// Use your own player for video renderingconst videoElement = document.getElementById('video-element');videoElement.srcObject = new MediaStream([videoTrack]);videoElement.play();
trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, async ({ userId, streamType }) => {// Only pull the stream, do not play itawait trtc.startRemoteVideo({ userId, streamType })const videoTrack = trtc.getVideoTrack({ userId, streamType });// Use your own player for video renderingconst videoElement = document.getElementById('remote-video-element');videoElement.srcObject = new MediaStream([videoTrack]);videoElement.play();});
Feedback