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
LocalMedia.GetAudioSourceInputs().Then(...);
LocalMedia.GetVideoSourceInputs().Then(...);
MediaTrack.GetSourceInputs
AudioTrack.GetSourceInputs().Then(...);
VideoTrack.GetSourceInputs().Then(...);
MediaSource.GetInputs
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
RemoteMedia.GetAudioSinkOutputs().Then(...);
RemoteMedia.GetVideoSinkOutputs().Then(...);
MediaTrack.GetSinkOutputs
These methods call into the underlying AudioTrack
or VideoTrack
of the RemoteMedia
.
AudioTrack.GetSinkOutputs().Then(...);
VideoTrack.GetSinkOutputs().Then(...);
MediaSink.GetOutputs
These methods call into the underlying AudioSink
or VideoSink
of the MediaTrack
(non-JavaScript only).
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.
LocalMedia.ChangeAudioSourceInput()
LocalMedia.ChangeVideoSourceInput()
Track Change Source Input
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.
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
RemoteMedia.ChangeAudioSinkOutput()
RemoteMedia.ChangeVideoSinkOutput()
Change Sink Output
These methods call into the underlying AudioSink
or VideoSink
of the MediaTrack
(for non-JavaScript environments only).
AudioSink.ChangeOutput()
VideoSink.ChangeOutput()
Monitor Audio Levels
Use the following to attach an event handler to LocalMedia/RemoteMedia.OnAudioLevel
.
Media.OnAudioLevel
media.OnAudioLevel += (level) =>
{
// level ranges from 0.0-1.0.
};
AudioTrack.OnLevel
media.AudioTrack.OnLevel += (level) =>
{
// level ranges from 0.0-1.0
};
Adjust Audio Levels
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;
Monitor Video Size
Use LocalMedia.Videosize
or RemoteMedia.VideoSize
to get the local or remote video size.
Media.VideoSize
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.
media.OnVideoSize += (size) =>
{
var width = size.Width;
var height = size.Height;
};
VideoTrack.Size
Alternatively, you can check VideoTrack.Size
.
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.
media.VideoTrack.OnSize += (size) =>
{
var width = size.Width;
var height = size.Height;
};