This document describes how to subscribe to the audio/video streams of another user in the room, i.e., how to play back the audio/video of another user. For the sake of convenience, "another user in the room" is called a "remote user" in this document.
Import the SDK and configure the application permissions as instructed in iOS.
You can call the setDefaultStreamRecvMode API in TRTCCloud
to set the subscription mode. TRTC provides two subscription modes:
Note:If you do not call
setDefaultStreamRecvMode
, the automatic subscription mode will be used. However, if you want to use the manual subscription mode, note thatsetDefaultStreamRecvMode
can take effect only if it is called beforeenterRoom
.
Make the current user enter a TRTC room as instructed in Entering a Room. A user can subscribe to the audio/video streams of a remote user only after a successful room entry.
You can call muteRemoteAudio("denny", true)
to mute the remote user denny
and then call muteRemoteAudio("denny", false)
to unmute denny
.
// Mute the user with ID denny
mCloud.muteRemoteAudio("denny", true);
// Unmute the user with ID denny
mCloud.muteRemoteAudio("denny", false);
You can call startRemoteView
to play back the video of a remote user, but only after you pass in a view object to the SDK as the rendering control that carries the user's video image.
The first parameter of startRemoteView
is userId
of the remote user, the second is the stream type of the user, and the third is the view object to be passed in. The second parameter streamType
has three valid values:
enableEncSmallVideoStream
). The high quality stream and low quality stream cannot be played back at the same time.You can call the stopRemoteView
API to stop playing back the video of one remote user or call the stopAllRemoteView
API to stop playing back videos of all remote users.
// Play back the camera (primary stream) image of `denny`
mCloud.startRemoteView("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, cameraView);
// Play back the screen sharing (substream) image of `denny`
mCloud.startRemoteView("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB, screenView);
// Play back the lower quality video image of `denny` (The high quality stream and low quality stream cannot be played back at the same time)
mCloud.startRemoteView("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL, cameraView);
// Stop playing back the camera image of `denny`
mCloud.stopRemoteView("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, cameraView);
// Stop playing back the video images of all remote users
mCloud.stopAllRemoteView();
You can call the updateRemoteView
API to change the view object during playback. This is useful for switching the video rendering control.
You can use setRemoteRenderParams
to set the video image fill mode, rotation angle, and mirror mode.
// Switch the primary stream image of `denny` to a small floating window (`miniFloatingView`)
mCloud.updateRemoteView("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, miniFloatingView);
// Set the fill mode of the primary stream image of the remote user `denny` to fill, and disable mirror mode
TRTCCloudDef.TRTCRenderParams param = new TRTCCloudDef.TRTCRenderParams();
param.fillMode = TRTCCloudDef.TRTC_VIDEO_RENDER_MODE_FILL;
param.mirrorType = TRTCCloudDef.TRTC_VIDEO_MIRROR_TYPE_DISABLE;
mCloud.setRemoteRenderParams("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, param);
In steps 4 and 5, you can control the audio/video playback of remote users. However, if there isn't sufficient information, you won’t be able to know:
To solve this problem, you need to listen for the following event callbacks from the SDK:
Audio status change notification (onUserAudioAvailable)
Listen for onUserAudioAvailable(userId,boolean)
to be notified when a remote user turns their mic on/off.
Video status change notification (onUserVideoAvailable)
Listen for onUserVideoAvailable(userId,boolean) to be notified when a remote user turns their camera on/off. Listen for
onUserSubStreamAvailable(userId,boolean)` to be notified when a remote user enables/disables screen sharing.
User room entry/exit notification (onRemoteUserEnter/LeaveRoom)
When a remote user enters the current room, you can use onRemoteUserEnterRoom(userId)
to get userId
of the user. When a remote user exits the current room, you can use onRemoteUserLeaveRoom(userId, reason)
to get userId
of the user and the reason for the exit.
Note:More accurately,
onRemoteUserEnter/LeaveRoom
is triggered only when an anchor enters/leaves the room. This prevents the problem of receiving frequent notifications of room entries/exits when there are a high number of audience members in the room.
With the event callbacks above, you can know the users in the room and whether they have turned on their cameras and mics. In the sample code below, mCameraUserList
, mMicrophoneUserList
, and mUserList
are used to maintain the following information respectively:
// Get the change of the video status of a remote user and update the list of users who have turned on their cameras (`mCameraUserList`)
@Override
public void onUserVideoAvailable(String userId, boolean available) {
available?mCameraUserList.add(userId) : mCameraUserList.remove(userId);
}
// Get the change of the audio status of a remote user and update the list of users who have turned on their mics (`mMicrophoneUserList`)
@Override
public void onUserAudioAvailable(String userId, boolean available) {
available?mMicrophoneUserList.add(userId) : mMicrophoneUserList.remove(userId);
}
// Get the room entry notification of a remote user and update the remote user list (`mUserList`)
@Override
public void onRemoteUserEnterRoom(String userId) {
mUserList.add(userId);
}
// Get the room exit notification of a remote user and update the remote user list (mUserList)
@Override
public void onRemoteUserLeaveRoom(String userId, int reason) {
mUserList.remove(userId);
}
There are three muting methods which work in completely different ways:
Method 1. The player stops subscribing to the audio stream
To stop playing back the audio of the remote user denny
, you can call muteRemoteAudio("denny", true)
, and the SDK will stop pulling audio data from denny
. In this mode, less traffic is used. However, because the SDK needs to restart the audio data pull process to resume audio playback, switching from the muted to unmuted status is slow.
Method 2. Adjust the playback volume level to zero
If you need to switch between the muted and unmuted status more quickly, you can use setRemoteAudioVolume("denny", 0)
, which sets the playback volume level of the remote user denny
to zero. Because this API doesn't involve network operations, it takes effect very quickly.
Method 3. The remote user turns off the mic
All operations described in this document are performed in the player and take effect only for the local user. For example, if you call muteRemoteAudio("denny", true)
to mute the remote user denny
, other users in the room can still hear denny
.
To completely disable the audio of denny
, you need to change the way their audio is published. For more information, see Publishing Audio/Video Streams.
Was this page helpful?