logo
Video Call
On this page

Multi-Source Capture

2024-09-20

Feature Overview

Multi-Source Capture is used to manage the audio and video source configurations of each channel. Through this capability, you can flexibly and quickly implement real-time interaction of different audio and video content, such as screen sharing, audio mixing, etc.

The main capabilities and limitations of Multi-Source Capture are as follows:

  • The publishing channel supports setting multiple audio and video sources, but the same audio and video source can only be occupied by one channel.
  • The main channel's audio and video sources support dynamic switching, and also support audio mixing capabilities. The auxiliary channel only supports specifying the capture source before publishing stream, and does not support audio mixing.
  • When capturing screen, only iOS and Android platforms support capturing both video and audio at the same time; other platforms only support capturing video. If you need to capture audio, please implement the relevant logic yourself.

Example Source Code

Please refer to Download Example Source Code to get the source code.

For related source code, please check the files in the "/ZegoExpressExample/Others/src/main/java/com/example/others/multivideosource" directory.

Prerequisites

Before using the Multi-Source Capture feature, please ensure:

Implementation Process

Warning

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

1 Create ZegoExpressEngine engine

For the process of creating a ZegoExpressEngine engine, please refer to Create Engine for implementing video call.

// Create a ZegoExpress instance and listen for common events
    void createEngine() {
        // Create an engine, access the general scenario, and register self as the eventHandler callback
        // If you don't need to register a callback, the eventHandler parameter can be passed null, and you can call the "setEventHandler:" method later to set the callback
        ZegoEngineProfile profile = new ZegoEngineProfile();
        profile.appID = appID;  // Please obtain through official website registration, format: 1234567890L
        profile.appSign = appSign; // Please obtain through official website registration, format: @"0123456789012345678901234567890123456789012345678901234567890123" (64 characters in total)
        profile.scenario = ZegoScenario.BROADCAST;  // Specify the use of the live streaming scenario (please fill in the scenario suitable for your business according to the actual situation)
        profile.application = getApplication();
        engine = ZegoExpressEngine.createEngine(profile, null);
    }

2 Set audio and video capture sources

  1. Call the setVideoSource interface to set the video capture source.
/** Use camera as video capture source */
engine.setVideoSource(ZegoVideoSourceType.CAMERA);
Notes
  1. Call the setAudioSource interface to set the audio capture source.

    • Set audio capture source only
    /** Use microphone as audio capture source */
    engine.setAudioSource(ZegoAudioSourceType.MICROPHONE);
    • Set audio capture source and set audio mixing configuration at the same time
    ZegoAudioSourceMixConfig audioSourceMixConfig = new ZegoAudioSourceMixConfig();
    
    /** Mix the sound played by the media player with sequence number 0*/
    audioSourceMixConfig.mediaPlayerIndexList = new int[1];
    audioSourceMixConfig.mediaPlayerIndexList[0] = 0;
    
    /** Mix the sound played by the audio effect player with sequence number 0*/
    audioSourceMixConfig.audioEffectPlayerIndexList = new int[1];
    audioSourceMixConfig.audioEffectPlayerIndexList[0] = 0;
    
    /** Use microphone as audio capture source and set audio mixing configuration */
    engine.setAudioSource(ZegoAudioSourceType.MICROPHONE, audioSourceMixConfig);
Notes

3 Login Room and publish stream

For the process of logging in to Room and publishing stream, please refer to Login Room and Publish Stream for implementing video call.

4 (Optional) Switch audio and video capture sources

  1. Call the setVideoSource interface to switch the video capture source.
/** Use screen sharing as video capture source */
engine.setVideoSource(ZegoVideoSourceType.SCREEN_CAPTURE);
  1. Call the setAudioSource interface to switch the audio capture source.
/** Use media player as audio capture source */
engine.setAudioSource(ZegoAudioSourceType.MEDIA_PLAYER);

5 Stop publishing stream

For the process of stopping publishing stream, please refer to Stop Publishing and Playing Stream for implementing video call.

/** Stop publishing stream */
engine.stopPublishingStream();

FAQ

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

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

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

  1. The main channel cannot use the media player's video or audio source.
  2. When the auxiliary channel uses a media player as the audio and video source, the main channel needs to use and start the microphone device (enableMicrophone). If you do not need microphone audio on the main channel, you can disable audio publishing through mutePublishStreamAudio while keeping the microphone enabled.
  3. Only when the main channel uses the 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 cannot be rendered.

Previous

Network Speed Test

Next

Publish Multiple Streams Simultaneously