Class PlatformAudio
- Namespace
- LiveKit
public sealed class PlatformAudio : IDisposable
- Inheritance
-
PlatformAudio
- Implements
- Inherited Members
- Extension Methods
Constructors
PlatformAudio()
Creates a new PlatformAudio instance, enabling the platform ADM.
This must be called before creating any PlatformAudioSource or connecting to a room if you want automatic speaker playout for remote audio.
On iOS, this automatically configures the audio session for VoIP mode (PlayAndRecord category with VoiceChat mode) to enable hardware echo cancellation and microphone input.
public PlatformAudio()
Exceptions
- InvalidOperationException
Thrown if the platform ADM could not be initialized (e.g., no audio devices, missing permissions).
Properties
PlayoutDeviceCount
Number of available playout (speaker) devices.
public int PlayoutDeviceCount { get; }
Property Value
RecordingDeviceCount
Number of available recording (microphone) devices.
public int RecordingDeviceCount { get; }
Property Value
Methods
Dispose()
Releases the PlatformAudio resources.
When disposed, the platform ADM may be disabled if this was the last PlatformAudio instance.
public void Dispose()
GetDevices()
Gets the lists of available recording and playout devices.
Platform behavior:
- Desktop (Windows/macOS/Linux): returns the full list of microphones and speakers reported by the OS. Devices can be selected with SetRecordingDevice(string) / SetPlayoutDevice(string).
- iOS and Android: returns a single placeholder entry at index 0 for each list, representing the system's currently selected default input/output. The OS owns audio routing on these platforms (AVAudioSession on iOS, AudioManager on Android), so individual devices are not enumerated and selecting one is a no-op (see SetRecordingDevice(string) / SetPlayoutDevice(string)).
public (List<AudioDevice> Recording, List<AudioDevice> Playout) GetDevices()
Returns
- (List<AudioDevice> Recording, List<AudioDevice> Playout)
A tuple containing:
- Recording: List of available microphones (on iOS/Android, a single placeholder for the OS default input)
- Playout: List of available speakers/headphones (on iOS/Android, a single placeholder for the OS default output)
Exceptions
- InvalidOperationException
Thrown if device enumeration failed.
SetPlayoutDevice(string)
Sets the playout device (speaker/headphones) by device ID (GUID).
On Android and iOS this is a no-op in the native ADM: output routing is governed by the OS (AVAudioSession on iOS, AudioManager on Android) and the call is acknowledged but ignored. The method is still safe to call, and the response carries no error. GetDevices() only exposes a single placeholder entry (index 0) for the OS default output on these platforms, so there is nothing else to select.
public void SetPlayoutDevice(string deviceId)
Parameters
deviceIdstringDevice ID/GUID from GetDevices().Playout[i].Guid
Exceptions
- InvalidOperationException
Thrown if the device is not found or the operation failed.
SetPlayoutDevice(uint)
Sets the playout device (speaker/headphones) by index.
Convenience wrapper around SetPlayoutDevice(string) that looks up the GUID from GetDevices(). Prefer the GUID overload for code that persists a selection — indices can shift when devices are added/removed.
public void SetPlayoutDevice(uint index)
Parameters
indexuintDevice index from GetDevices().Playout
Exceptions
- InvalidOperationException
Thrown if the device index is out of range or the operation failed.
SetRecordingDevice(string)
Sets the recording device (microphone) by device ID (GUID).
On Android and iOS this is a no-op in the native ADM: input routing is governed by the OS (AVAudioSession on iOS, AudioManager on Android) and the call is acknowledged but ignored. The method is still safe to call, and the response carries no error. GetDevices() only exposes a single placeholder entry (index 0) for the OS default input on these platforms, so there is nothing else to select.
public void SetRecordingDevice(string deviceId)
Parameters
deviceIdstringDevice ID/GUID from GetDevices().Recording[i].Guid
Exceptions
- InvalidOperationException
Thrown if the device is not found or the operation failed.
SetRecordingDevice(uint)
Sets the recording device (microphone) by index.
Convenience wrapper around SetRecordingDevice(string) that looks up the GUID from GetDevices(). Prefer the GUID overload for code that persists a selection — indices can shift when devices are added/removed.
public void SetRecordingDevice(uint index)
Parameters
indexuintDevice index from GetDevices().Recording
Exceptions
- InvalidOperationException
Thrown if the device index is out of range or the operation failed.
StartRecording()
Starts recording from the microphone.
Recording is started automatically when PlatformAudio is created. Use this to resume recording after calling StopRecording. This turns on the system's recording privacy indicator (e.g., on macOS/iOS).
public IEnumerator StartRecording()
Returns
Exceptions
- InvalidOperationException
Thrown if the operation failed.
StopRecording()
Stops recording from the microphone.
Use this to temporarily stop recording without disposing PlatformAudio. This turns off the system's recording privacy indicator (e.g., on macOS/iOS). Call StartRecording to resume recording.
public void StopRecording()
Exceptions
- InvalidOperationException
Thrown if the operation failed.