Search Results for

    Show / Hide Table of Contents

    Manage Audio and Video

    Note

    About the code examples for the Control Media Capture section:

    • For Unity, use the C# code.

    Use the methods on this page to manage audio and video in LiveSwitch.

    Get Input Audio or Video Devices

    Use the following asynchronous methods in the LocalMedia class to return arrays of audio and video input devices.

    LocalMedia.GetMediaSourceInput

    • CSharp
    LocalMedia.GetAudioSourceInputs().Then(...);
    LocalMedia.GetVideoSourceInputs().Then(...);
    

    MediaTrack.GetSourceInputs

    • CSharp
    AudioTrack.GetSourceInputs().Then(...);
    VideoTrack.GetSourceInputs().Then(...);
    

    MediaSource.GetInputs

    • CSharp
    AudioSource.GetInputs().Then(...);
    VideoSource.GetInputs().Then(...);
    

    Get Output Audio or Video Devices

    Use the following asynchronous methods in the RemoteMedia class to return arrays of audio and video output devices.

    RemoteMedia.GetMediaSinkOutputs

    • CSharp
    • JavaScript
    RemoteMedia.GetAudioSinkOutputs().Then(...);
    RemoteMedia.GetVideoSinkOutputs().Then(...);
    
    RemoteMedia.getAudioSinkOutputs().then(...);
    RemoteMedia.getVideoSinkOutputs().then(...);
    

    MediaTrack.GetSinkOutputs

    These methods call into the underlying AudioTrack or VideoTrack of the RemoteMedia.

    • CSharp
    • JavaScript
    AudioTrack.GetSinkOutputs().Then(...);
    VideoTrack.GetSinkOutputs().Then(...);
    
    AudioTrack.getSinkOutputs().then(...);
    VideoTrack.getSinkOutputs().then(...);
    

    MediaSink.GetOutputs

    These methods call into the underlying AudioSink or VideoSink of the MediaTrack (non-JavaScript only).

    • CSharp
    • JavaScript
    AudioSink.GetOutputs().Then(...);
    VideoSink.GetOutputs().Then(...);
    
    AudioSink.getOutputs().then(...);
    VideoSink.getOutputs().then(...);
    

    Change Input Audio or Video Devices

    Use the following asynchronous methods in the LocalMedia class to change the audio and video input devices.

    LocalMedia Change Source Input

    These methods change the media source input of the media track while the media is active. If there are multiple media tracks in a custom media stack, these methods call into the first track.

    • CSharp
    LocalMedia.ChangeAudioSourceInput()
    LocalMedia.ChangeVideoSourceInput()
    

    Track Change Source Input

    • CSharp
    AudioTrack.ChangeSourceInput()
    VideoTrack.ChangeSourceInput()
    

    Source Change Input

    These methods call into the underlying AudioSource or VideoSource of the MediaTrack.

    Note

    These methods are not for browser environments.

    • CSharp
    AudioSource.ChangeInput()
    VideoSource.ChangeInput()
    

    Change Output Audio or Video Devices

    Use the following asynchronous methods in the RemoteMedia class to change audio and video output devices.

    Change RemoteMedia Sink Output

    • CSharp
    • JavaScript
    RemoteMedia.ChangeAudioSinkOutput()
    RemoteMedia.ChangeVideoSinkOutput()
    
    RemoteMedia.changeAudioSinkOutput()
    RemoteMedia.changeVideoSinkOutput()
    

    Change Sink Output

    These methods call into the underlying AudioSink or VideoSink of the MediaTrack (for non-JavaScript environments only).

    • CSharp
    • JavaScript
    AudioSink.ChangeOutput()
    VideoSink.ChangeOutput()
    
    AudioSink.changeOutput()
    VideoSink.changeOutput()
    

    Monitor Audio Levels

    Use the following to attach an event handler to LocalMedia/RemoteMedia.OnAudioLevel.

    Media.OnAudioLevel

    • CSharp
    media.OnAudioLevel += (level) =>
    {
        // level ranges from 0.0-1.0.
    };
    

    AudioTrack.OnLevel

    • CSharp
    media.AudioTrack.OnLevel += (level) =>
    {
        // level ranges from 0.0-1.0
    };
    

    Adjust Audio Levels

    • CSharp
    • JavaScript

    The following AudioTrack properties affect audio levels:

    • Volume: Affects hardware. For example, Volume can affect the speaker's level.
    • Gain: Affects software. For example, Gain adjusts the amplitude of the signal in the track which also affects the remote side.
    Note

    Increasing Gain increases the signal's overall amplitude, including any noise in the signal. Increasing Gain too much can result in unusable audio due to the increased noise.

    LocalMedia.AudioTrack.Volume

    To increase Volume levels, adjust the AudioTrack.Volume property by giving it a value from 0 (min) to 1 (max).

    For example:

    LocalMedia.AudioTrack.Volume = .5;
    

    LocalMedia.AudioTrack.Gain

    To increase Gain levels, adjust the AudioTrack.Gain property by giving it a value from 0 (min) to 1 (max).

    For example:

    LocalMedia.AudioTrack.Gain = .5;
    

    The following code sample shows how to adjust audio level in JavaScript:

    localMedia.addOnAudioLevel(async (level) => { // Level is a percent. 
      if (level * 100 > 3) {
         mainDiv.style.border = "3px solid red"; 
        } 
      else 
       { 
        mainDiv.style.border = "none";
       }
     });
    
    remoteMedia.setAudioVolume(volume / 100);
    

    Monitor Video Size

    Use LocalMedia.Videosize or RemoteMedia.VideoSize to get the local or remote video size.

    Media.VideoSize

    • CSharp
    var size = media.VideoSize;
    var width = size.Width;
    var height = size.Height;
    

    Media.OnVideoSize

    You can also subscribe to the LocalMedia.OnVideoSize or RemoteMedia.OnVideoSize events.

    • CSharp
    media.OnVideoSize += (size) =>
    {
        var width = size.Width;
        var height = size.Height;
    };
    

    VideoTrack.Size

    Alternatively, you can check VideoTrack.Size.

    • CSharp
    var size = media.VideoTrack.Size;
    var width = size.Width;
    var height = size.Height;
    

    VideoTrack.OnSize

    You can also monitor video size by subscribing to the VideoTrack.OnSize event.

    • CSharp
    media.VideoTrack.OnSize += (size) =>
    {
        var width = size.Width;
        var height = size.Height;
    };
    
    In This Article
    Back to top Copyright © LiveSwitch Inc. All Rights Reserved.Documentation for LiveSwitch Version 1.6.2