tencent cloud

Tencent Real-Time Communication

Web

다운로드
포커스 모드
폰트 크기
마지막 업데이트 시간: 2023-09-26 16:59:51
This document describes how to subscribe to the audio/video streams of another user (remote user) in the room, i.e., how to play the audio/video of a remote user.



Step 1. Enter Room

For detailed directions, see Enter Room.

Step 2. Play Remote Audio and Video

Play Remote Audio

By default, the SDK will automatically play remote audio, and you do not need to call any API to play remote audio.

If you do not want the SDK to automatically play remote audio, you can

1. Set autoReceiveAudio = false to turn off automatic audio playback by calling trtc.enterRoom({ autoReceiveAudio: false }).
2. Listen for the TRTC.EVENT.REMOTE_AUDIO_AVAILABLE event before entering the room.
3. Save the userId of remote user when this event fired.
4. Call trtc.muteRemoteAudio(userId, false)method when you need to play remote audio.
Note:
If the user has not interacted with the page before entering the room, automatic audio playback may fail due to Browser's Autoplay Policy. You need to refer to the Handle Autoplay Restriction for processing.

Play Remote Video

1. Listen for the TRTC.EVENT.REMOTE_VIDEO_AVAILABLE event before entering the room to receive all remote user video publishing events.
2. Use the trtc.startRemoteVideo() method to play the remote video stream when you receive the event.
trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {
// To play the video image, you need to place an HTMLElement in the DOM, which can be a div tag, assuming its id is `${userId}_${streamType}`
const view = `${userId}_${streamType}`;
trtc.startRemoteVideo({ userId, streamType, view });
});


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백