tencent cloud


Last updated: 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.
    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 });
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support