Parrot.Media.AudioDevices (Parrot Platform v0.0.1-alpha.3)

Manages audio device discovery and selection for PortAudio integration.

This module provides functions to list available audio devices, get default devices, and validate device IDs for use with Membrane's PortAudio plugin.

Example

iex> Parrot.Media.AudioDevices.list_devices()
{:ok, [
  %{id: 0, name: "Built-in Microphone", type: :input, channels: 2},
  %{id: 1, name: "Built-in Output", type: :output, channels: 2}
]}

iex> Parrot.Media.AudioDevices.get_default_input()
{:ok, 0}

Summary

Functions

Gets the default input device ID.

Gets the default output device ID.

Gets device information by ID.

Lists all available audio devices.

Prints available audio devices to console.

Validates if a device ID exists and matches the expected type.

Types

device_info()

@type device_info() :: %{
  id: non_neg_integer(),
  name: String.t(),
  type: :input | :output,
  channels: non_neg_integer()
}

Functions

get_default_input()

@spec get_default_input() :: {:ok, non_neg_integer()} | {:error, term()}

Gets the default input device ID.

Since device enumeration is not available, this returns the typical default input device ID. You may need to adjust this based on your system configuration. Use print_devices/0 to see actual device IDs.

get_default_output()

@spec get_default_output() :: {:ok, non_neg_integer()} | {:error, term()}

Gets the default output device ID.

Since device enumeration is not available, this returns the typical default output device ID. You may need to adjust this based on your system configuration. Use print_devices/0 to see actual device IDs.

get_device_info(device_id)

@spec get_device_info(non_neg_integer()) :: {:ok, device_info()} | {:error, term()}

Gets device information by ID.

Since device enumeration is not available, this returns a stub response. Use print_devices/0 to see actual device information.

list_devices()

@spec list_devices() :: {:ok, [device_info()]} | {:error, term()}

Lists all available audio devices.

NOTE: The current version of membrane_portaudio_plugin doesn't provide programmatic access to device enumeration. Use print_devices/0 to see available devices in the console.

Returns a stub response for compatibility.

validate_device(device_id, expected_type)

@spec validate_device(non_neg_integer(), :input | :output) :: :ok | {:error, term()}

Validates if a device ID exists and matches the expected type.

Since device enumeration is not available, this performs basic validation based on common device ID patterns. Use print_devices/0 to verify actual device IDs and types on your system.

Parameters

  • device_id - The device ID to validate
  • expected_type - Either :input or :output

Returns

  • :ok if the device ID is in a reasonable range
  • {:error, reason} otherwise