please select
RTC Engine
  • Overview
  • Web
    • Run Sample Demo
    • Integration
    • Basic Features
      • Screen Sharing
      • Live Streaming
      • Media Device
      • Audio Volume
      • Set Encoding Profile
      • Detect Network Quality
      • Detect Capabilities
    • Advance Features
      • Enable AI Denoiser
      • Enable Audio Mixer
      • Enable Watermark
      • Enable Virtual Background
      • Enable Beauty and Effects
      • Data Messages
      • Custom Capturing and Rendering
    • API List
    • Released Notes
    • Supported Platforms
    • Web FAQs
      • Optimize Multi-Person Video Calls
      • Handle Autoplay Restriction
      • Handle Firewall Restriction
      • Others
  • Android
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Newwork Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCStatistics
      • TRTCCloudListener
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • Error Codes
    • Solution
      • Real-Time Chorus (TUIKaraoke)
        • Quick Integration
        • Implementation Steps
        • Song Synchronization
        • Lyric Synchronization
        • Vocal Synchronization
        • Mixing Stream Solution
        • TRTCKaraoke APIs
        • FAQs
    • Release Notes
  • iOS
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Network Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • ErrorCode
    • Solution
      • Quick Integration
      • Implementation Steps
      • Song Synchronization
      • Lyric Synchronization
      • Vocal Synchronization
      • Mixing Stream Solution
      • TRTCKaraoke APIs
      • FAQs
    • Release Notes
  • macOS
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Sharing Computer Audio
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Hardware Devices
      • Testing Network Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • ErrorCode
      • Release Notes
    • Release Notes
  • Windows
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Hardware Devices
      • Testing Network Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • ITRTCCloud
      • ITRTCStatistics
      • TRTCCloudCallback
      • ITXAudioEffectManager
      • ITXDeviceManager
      • Type Definition
      • Deprecated Interface
      • Error Codes
    • Release Notes
  • Electron
    • Integration
      • 1.API Examples
      • 2.Importing the SDK
      • 3.Entering a Room
      • 4.Subscribing to Audio/Video Streams
      • 5.Publish Audio/Video Streams
      • 6.Exiting a Room
      • 7.Sensing Network Quality
      • 8.Enabling Screen Sharing
      • 9.Sharing Computer Audio
      • 10.Setting Video Quality
      • 11.Rotating Videos
    • Client APIs
      • Overview
      • Error Codes
  • Flutter
    • Integration
      • 1.API Examples
      • 2.Importing the SDK
      • 3.Entering a Room
      • 4.Subscribing to Audio/Video Streams
      • 5.Publish Audio/Video Streams
      • 6.Exiting a Room
      • 7.Sensing Network Quality
      • 8.Enabling Screen Sharing
      • 9.Sharing Computer Audio
      • 10.Setting Video Quality
      • 11.Rotating Videos
    • Client APIs
      • Overview
      • Error Codes
  • Unity
    • Integration
      • 1.API Examples
      • 2Importing the SDK
    • Client APIs
      • Overview
      • Error Codes
  • Qt
    • Integration
      • 1.Importing the SDK
  • Overview
    • Overview
  • Concepts
  • Features
  • Performance Statistics
  • Pricing
    • Free Minutes
    • RTC-Engine Monthly Packages
    • Billing Explanation for Subscription Package Duration
    • Pay-as-you-go
      • Billing of Audio and Video Duration
      • Billing of On-Cloud Recording and Recording Delivery
      • Billing of MixTranscoding and Relay to CDN
  • FAQs
    • FAQs for Beginners
    • Migration Guide
      • Twilio Video to Tencent RTC
      • Billing
      • Features
      • UserSig
      • Firewall Restrictions
      • How to Downsize Installation Package
      • TRTCCalling for Web
      • Audio and Video Quality
      • Others
RTC Engine

Live Streaming

This tutorial mainly introduces how to implement the Live Streaming by using scene live.

Demo



TRTC Scene and Roles

In general business scenarios, not all users need to publish streams, and some users only need to subscribe streams.

There are two types of scene in TRTC
Scene rtc: Default scene. All users in rtc scene are anchors, and there are no audience role in this scene.
Scene live: Users in this scene can be divided into two roles, the anchor and the audience. The difference between the two roles is:
The anchor can publish the stream. A room supports up to 50 anchors to publish streams at the same time.
The audience can not publish the stream. There is no limit on the number of audiences.

Anchor Side

The process of implementing audio and video calls on the anchor side is basically the same as the implementation process of the rtc scene. Refer to: Basic Audio/Video Call.

The main difference is the parameters scene and role set when calling trtc.enterRoom(). Refer to the following sample code:
await trtc.enterRoom({
scene: TRTC.TYPE.SCENE_LIVE,
role: TRTC.TYPE.ROLE_ANCHOR,
sdkAppId,
userId,
userSig,
roomId
});

Audience Side

Enter the Room as an Audience

Set the role parameter to TRTC.TYPE.ROLE_AUDIENCE.
await trtc.enterRoom({
scene: TRTC.TYPE.SCENE_LIVE,
role: TRTC.TYPE.ROLE_AUDIENCE,
sdkAppId,
userId,
userSig,
roomId
});

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.
Autoplay Policy Restriction
If the user has not interacted with the page before entering the room, automatic audio playback may fail due to Autoplay Policy Restriction. You need to refer to the Handle Autoplay Restriction for processing.
If you do not want the SDK to automatically play audio, you can try this:
trtc.on(TRTC.EVENT.REMOTE_AUDIO_AVAILABLE, event => {
// Call this api when you need to play remote audio.
trtc.muteRemoteAudio(event.userId, false);
// Stop remote audio
trtc.muteRemoteAudio(event.userId, true);
})
// Setting autoReceiveAudio = false to turn off automatic audio playback.
await trtc.enterRoom({ ..., autoReceiveAudio: false });

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. Call trtc.startRemoteVideo() 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 });
});

How to Switch Role

The audience role does not have the permission to publish stream, so if the audience wants to make a call with the anchor, they need to switch to the anchor role by using trtc.switchRole and then publish streams.
// Switch to the anchor
await trtc.switchRole(TRTC.TYPE.ROLE_ANCHOR);

// Turn on mic and camera, then the other anchor in the room will able to receive your audio and video.
await trtc.startLocalAudio();
await trtc.startLocalVideo();

// Switch back to the audience when the calling is ended
await trtc.switchRole(TRTC.TYPE.ROLE_AUDIENCE);