logo
Video Call
On this page

Multi-Source Capture

2024-09-20

Function Overview

Multi-source capture is used to manage audio/video source configurations for each channel. Through this capability, you can flexibly and quickly implement real-time interaction of different audio/video content, such as screen sharing, audio mixing, and other functions.

The main capabilities and limitations of multi-source capture are as follows:

  • Publishing channels support setting multiple audio/video sources, but the same audio/video source can only be occupied by one channel.
  • The main channel's audio/video source supports dynamic switching and audio mixing capabilities. Auxiliary channels only support specifying capture sources before publishing streams and do not support mixing.
  • When capturing screens, only iOS and Android platforms support simultaneous video and audio capture; other platforms only support video capture. If audio capture is required, developers need to implement the relevant logic themselves.

Prerequisites

Before using the multi-source capture feature, ensure that:

Implementation Process

Warning

Real-time audio products only support setting audio capture sources.

1 Create ZegoExpressEngine Engine

For the ZegoExpressEngine engine creation process, please refer to Create Engine for implementing video calls.

// Create ZegoExpress instance and listen to common events
    void createEngine() {
        // Create engine for general scenario access
        // appID: Obtain through official website registration, format: 1234567890L
        // appSign: Obtain through official website registration, format: @"0123456789012345678901234567890123456789012345678901234567890123" (64 characters total)
        // ZegoScenario.Broadcast specifies using live streaming scenario (please fill in the scenario suitable for your business)
        var profile = new ZegoEngineProfile(appID, ZegoScenario.Broadcast, appSign: appSign);
        ZegoExpressEngine.createEngineWithProfile(profile);
    }

2 Set Audio/Video Capture Sources

  1. Call the setVideoSource interface to set the video capture source.
/** Use camera as video capture source */
ZegoExpressEngine.instance.setVideoSource(ZegoVideoSourceType.ZegoVideoSourceCamera);
Note
  • If you need to use a media player as the video capture source, you need to first call the createMediaPlayer interface to create a media player, then call the setVideoSource interface to set the video capture source type to ZegoVideoSourceType.ZegoVideoSourcePlayer and set the media player instance index used by the video capture source, then use the newly created media player to load resources and play. For details, please refer to Media Player.
  • If you need to use screen sharing as the video capture source, you need to set the video capture source type to ZegoVideoSourceType.ZegoVideoSourceScreenCapture and enable screen sharing to push screen sharing video data to the SDK. For details, please refer to Screen Sharing.
  1. Call the setAudioSource interface to set the audio capture source.
/** Use microphone as audio capture source */
ZegoExpressEngine.instance.setAudioSource(ZegoAudioSourceType.Microphone);
Note
  • If you need to use custom audio capture as the audio capture source, you need to set the audio capture source type to ZegoAudioSourceType.Custom, and call interfaces such as sendCustomAudioCaptureAACData or sendCustomAudioCapturePCMData to send audio data to the SDK. For details, please refer to Custom Audio Capture and Rendering.
  • If you need to use a media player as the audio capture source, you need to set the audio capture source type to ZegoAudioSourceType.MediaPlayer, call the createMediaPlayer interface to create a media player, then use the newly created media player to load resources and play. For details, please refer to Media Player.

3 Login to Room and Publish Stream

For the room login and stream publishing process, please refer to Login Room and Publish Stream for implementing video calls.

4 (Optional) Switch Audio/Video Capture Sources

  1. Call the setVideoSource interface to switch the video capture source.
/** Use screen sharing as video capture source */
ZegoExpressEngine.instance.setVideoSource(ZegoVideoSourceType.ZegoVideoSourceScreenCapture);
  1. Call the setAudioSource interface to switch the audio capture source.
/** Use media player as audio capture source */
ZegoExpressEngine.instance.setAudioSource(ZegoAudioSourceType.MediaPlayer);

5 Stop Publishing Stream

For the stop publishing stream process, please refer to Stop Publishing/Playing Stream for implementing video calls.

// Stop publishing stream
ZegoExpressEngine.instance.stopPublishingStream();

API Reference List

MethodDescription
setVideoSourceSet video capture source
setAudioSourceSet audio capture source
sendCustomAudioCaptureAACDataSend custom captured AAC data to SDK
sendCustomAudioCapturePCMDataSend custom captured PCM data to SDK
createMediaPlayerCreate media player instance

FAQ

1. How to capture screen video and system audio?

If you need to capture screen video and system audio, please refer to Screen Sharing.

2. Do you support setting multiple media players?

Yes, but note that the same player instance can only be occupied by one channel.

3. What are the limitations when combining video sources and audio sources?

The limitations for combining video sources and audio sources are as follows:

  1. The main channel cannot use media player video or audio sources.
  2. When the auxiliary channel uses a media player as the audio/video source, the main channel needs to use and enable the microphone device (enableMicrophone). If you don't need microphone sound on the main channel, you can disable audio publishing while keeping the microphone enabled through mutePublishStreamAudio.
  3. Only when the main channel uses a camera video source or microphone audio source can the auxiliary channel copying the main channel video source or audio source take effect.
  4. The main channel's audio source cannot be set to None, otherwise the audio will not be able to render.

Previous

Network Testing

Next

Media Supplemental Enhancement Information (SEI)

On this page

Back to top