public void OnDeviceSelected(int index)
    {
        // Stop and destroy the current stream.
        if (_stream != null)
        {
            _stream.Dispose();
            _stream = null;
        }

        // Reset the UI elements.
        _channelList.ClearOptions();
        _channelList.RefreshShownValue();
        _statusText.text = "";

        // Break if the null device option was selected.
        if (_deviceList.value == 0)
        {
            return;
        }

        // Open a new stream.
        try
        {
            _stream = DeviceDriver.OpenInputStream(_deviceList.value - 1);
        }
        catch (System.InvalidOperationException e)
        {
            _statusText.text = $"Error: {e.Message}";
            return;
        }

        // Construct the channel list.
        _channelList.options =
            Enumerable.Range(0, _stream.ChannelCount).
            Select(i => $"Channel {i + 1}").
            Select(text => new Dropdown.OptionData()
        {
            text = text
        }).
            ToList();

        _channelList.RefreshShownValue();
    }