Your business scenarios might require you to set the publishing state of audio and video streams during real-time engagement.
This article describes how to the set the publishing state of local streams using C++. To use Java or Objective-C, see Corresponding methods in different programming languages.
Agora provides the following methods to set the publishing state of local streams:
| Method | Description |
|---|---|
enableLocalAudio or enableLocalVideo |
Sets whether to enable the local audio or video capture module:true: (Default) Enable the local audio or video capture module. After enabling a module, the SDK captures the local audio or video, and then users can choose whether to publish a local stream.false: Disable the local audio or video capture module. After disabling a module, the SDK does not capture the local audio or video, so no local stream can be published.If you only need to stop or resume publishing a local stream, Agora recommends calling muteLocalAudioStream or muteLocalVideoStream. |
muteLocalAudioStream or muteLocalVideoStream |
Sets whether to stop publishing a local stream:true: Stop publishing a local stream.false: Resume publishing a local stream. |
joinChannel with the options parameter |
When joining a channel, you can use the publishLocalAudio or publishLocalVideo member in ChannelMediaOptions to set the publishing state of local streams:true: (Default) Publish.false: Do not publish. |
setClientRole |
Sets the user role in an interactive live streaming channel:CLIENT_ROLE_AUDIENCE: (Default) Audience.CLIENT_ROLE_BROADCASTER: Host, who publishes local streams by default. |
joinChannel with the options parameter, muteLocalAudioStream or muteLocalVideoStream only takes effect when it is called after joinChannel.setClientRole(AUDIENCE), the user cannot publish local streams. No matter how you set the joinChannel with the options parameter, muteLocalAudioStream, or muteLocalVideoStream, the publishing state cannot be changed.setClientRole(BROADCASTER), joinChannel with the options parameter, muteLocalAudioStream, or muteLocalVideoStream together, the method called later determines the publishing state.As of v3.4.5, Agora adds the publishLocalAudio and publishLocalVideo members in ChannelMediaOptions. The default value is true. You can call joinChannel with the options parameter to join a channel and set the publishing state.
If you upgrade the SDK to v3.4.5 or later, to avoid affecting your service, take note of the following differences between versions and adjust your publishing settings accordingly.
Earlier than v3.4.5:
joinChannel methods can set the publishing state of local streams.muteLocalAudioStream and muteLocalVideoStream take effect when they are called before or after a user joins a channel.muteLocalAudioStream(true) or muteLocalVideoStream(true) in IRtcEngine takes effect in channels created by both the IRtcEngine and IChannel classes.As of v3.4.5:
joinChannel method with the options parameter can set the publishing state of local streams.joinChannel with the options parameter, muteLocalAudioStream or muteLocalVideoStream only takes effect when it is called after joinChannel.muteLocalAudioStream and muteLocalVideoStream in the IRtcEngine and IChannel classes control the publishing state of each channel in their respective classes only.| Windows | Android/React Native/Flutter | iOS/macOS |
|---|---|---|
enableLocalAudio |
enableLocalAudio |
enableLocalAudio |
enableLocalVideo |
enableLocalVideo |
enableLocalVideo |
muteLocalAudioStream |
muteLocalAudioStream |
muteLocalAudioStream |
muteLocalVideoStream |
muteLocalVideoStream |
muteLocalVideoStream |
joinChannel |
joinChannel |
joinChannelByToken |
setClientRole |
setClientRole |
setClientRole |
setChannelProfile |
setChannelProfile |
setChannelProfile |
IRtcEngine |
RtcEngine |
AgoraRtcEngineKit |
IChannel |
RtcChannel |
AgoraRtcChannel |
| Unity | Electron |
|---|---|
EnableLocalAudio |
enableLocalAudio |
EnableLocalVideo |
enableLocalVideo |
MuteLocalAudioStream |
muteLocalAudioStream |
MuteLocalVideoStream |
muteLocalVideoStream |
JoinChannel |
joinChannel |
SetClientRole |
setClientRole |
SetChannelProfile |
setChannelProfile |
IRtcEngine |
AgoraRtcEngine |
AgoraChannel |
AgoraRtcChannel |