private void OnSelectSpeaker(object sender, RoutedEventArgs e) { if (App.CurrentAccount == null || !_initialized) { return; } Console.WriteLine("Speaker Selected"); bool updateData = false; VATRPDevice selectedSpeaker = (VATRPDevice)SelectSpeakerComboBox.SelectedItem; string selectedSpeakerId = App.CurrentAccount.SelectedSpeakerId; if (string.IsNullOrEmpty(selectedSpeakerId)) { if (SelectSpeakerComboBox.Items.Count > 0) { var device = SelectSpeakerComboBox.Items.GetItemAt(0) as VATRPDevice; if (device != null) { updateData = true; App.CurrentAccount.SelectedSpeakerId = device.deviceId; selectedSpeakerId = device.deviceId; } } } if ((selectedSpeaker != null && selectedSpeaker.deviceId != selectedSpeakerId) || updateData) { if (selectedSpeaker != null) { App.CurrentAccount.SelectedSpeakerId = selectedSpeaker.deviceId; } ServiceManager.Instance.ApplyMediaSettingsChanges(); ServiceManager.Instance.SaveAccountSettings(); } }
private void DeviceSelected(object sender, SelectionChangedEventArgs e) { var selectedItem = DeviceListView.SelectedItem; if (selectedItem is VATRPDevice) { VATRPDevice device = DeviceListView.SelectedItem as VATRPDevice; if (OnDeviceSelected != null) { OnDeviceSelected(device); } } }
public override void Initialize() { base.Initialize(); if (App.CurrentAccount == null) { return; } /* List<VATRPDevice> cameraList = ServiceManager.Instance.GetAvailableCameras(); * string storedCameraId = App.CurrentAccount.SelectedCameraId; * if (cameraList != null) * { * List<string> cameraNames = new List<string>(); * foreach (VATRPDevice device in cameraList) * { * cameraNames.Add(device.displayName); * if (!string.IsNullOrEmpty(storedCameraId) && storedCameraId.Equals(device.deviceId)) * { * _selectedCamera = device.displayName; * } * } * Cameras = cameraNames.ToArray(); * } */ foreach (var item in PreferredVideoSizeComboBox.Items) { var tb = item as TextBlock; if (GetPreferredVideoSizeId(tb).Equals(App.CurrentAccount.PreferredVideoId)) { PreferredVideoSizeComboBox.SelectedItem = item; break; } } List <VATRPDevice> availableCameras = ServiceManager.Instance.GetAvailableCameras(); VATRPDevice selectedCamera = ServiceManager.Instance.GetSelectedCamera(); CameraList.Clear(); if (availableCameras == null) { return; } foreach (VATRPDevice camera in availableCameras) { CameraList.Add(camera); if ((selectedCamera != null) && selectedCamera.deviceId.Trim().Equals(camera.deviceId.Trim())) { SelectCameraComboBox.SelectedItem = camera; } } List <VATRPDevice> availableMicrophones = ServiceManager.Instance.GetAvailableMicrophones(); VATRPDevice selectedMicrophone = ServiceManager.Instance.GetSelectedMicrophone(); MicrophoneList.Clear(); foreach (VATRPDevice microphone in availableMicrophones) { MicrophoneList.Add(microphone); if ((selectedMicrophone != null) && selectedMicrophone.deviceId.Trim().Equals(microphone.deviceId.Trim())) { SelectMicrophoneComboBox.SelectedItem = microphone; } } List <VATRPDevice> availableSpeakers = ServiceManager.Instance.GetAvailableSpeakers(); VATRPDevice selectedSpeaker = ServiceManager.Instance.GetSelectedSpeakers(); SpeakerList.Clear(); foreach (VATRPDevice speaker in availableSpeakers) { SpeakerList.Add(speaker); if ((selectedSpeaker != null) && selectedSpeaker.deviceId.Trim().Equals(speaker.deviceId.Trim())) { SelectSpeakerComboBox.SelectedItem = speaker; } } /* string selectedCameraId = App.CurrentAccount.SelectedCameraId; * if (string.IsNullOrEmpty(selectedCameraId)) * { * VATRPDevice selectedCamera = ServiceManager.Instance.GetSelectedCamera(); * // SelectedCameraLabel.Content = selectedCamera.displayName; * // SelectedCameraLabel.ToolTip = selectedCamera.displayName; * } * else * { * foreach (VATRPDevice camera in availableCameras) * { * if (!string.IsNullOrEmpty(selectedCameraId) && selectedCameraId.Equals(camera.deviceId)) * { * SelectCameraComboBox.SelectedItem = camera; * // SelectedCameraLabel.Content = camera.displayName; * // SelectedCameraLabel.ToolTip = camera.displayName; * } * } * } * * List<VATRPDevice> availableMicrophones = ServiceManager.Instance.GetAvailableMicrophones(); * string selectedMicrophoneId = App.CurrentAccount.SelectedMicrophoneId; * if (string.IsNullOrEmpty(selectedMicrophoneId)) * { * VATRPDevice selectedMicrophone = ServiceManager.Instance.GetSelectedMicrophone(); * SelectedMicrophoneLabel.Content = selectedMicrophone.displayName; * SelectedMicrophoneLabel.ToolTip = selectedMicrophone.displayName; * } * else * { * foreach (VATRPDevice microphone in availableMicrophones) * { * if (!string.IsNullOrEmpty(selectedMicrophoneId) && selectedMicrophoneId.Equals(microphone.deviceId)) * { * SelectedMicrophoneLabel.Content = microphone.displayName; * SelectedMicrophoneLabel.ToolTip = microphone.displayName; * } * } * } * * List<VATRPDevice> availableSpeakers = ServiceManager.Instance.GetAvailableSpeakers(); * string selectedSpeakerId = App.CurrentAccount.SelectedSpeakerId; * if (string.IsNullOrEmpty(selectedSpeakerId)) * { * VATRPDevice selectedSpeaker = ServiceManager.Instance.GetSelectedSpeakers(); * SelectedSpeakerLabel.Content = selectedSpeaker.displayName; * SelectedSpeakerLabel.ToolTip = selectedSpeaker.displayName; * } * else * { * foreach (VATRPDevice speaker in availableSpeakers) * { * if (!string.IsNullOrEmpty(selectedSpeakerId) && selectedSpeakerId.Equals(speaker.deviceId)) * { * SelectedSpeakerLabel.Content = speaker.displayName; * SelectedSpeakerLabel.ToolTip = speaker.displayName; * } * } * } * */ }
// Note: if the selected device is not available, use the default, and store the default for the current user internal void ApplyMediaSettingsChanges() { // this should never be an issue, but just in case if (App.CurrentAccount == null) { return; } LinphoneService.LinphoneConfig.MediaEncryption = GetMediaEncryptionText(App.CurrentAccount.MediaEncryption); LinphoneService.UpdateMediaSettings(App.CurrentAccount); bool accountChanged = false; // prior to setting the devices we need to ensure that the selected devices are still options. // for example - did the user unplug the camera since the last run? if (!string.IsNullOrEmpty(App.CurrentAccount.SelectedCameraId)) { List <VATRPDevice> availableCameras = GetAvailableCameras(); if (IsDeviceAvailable(App.CurrentAccount.SelectedCameraId, availableCameras)) { LinphoneService.SetCamera(App.CurrentAccount.SelectedCameraId); } else { // update the stored setting in the account because the previously selected device is not available VATRPDevice device = GetSelectedCamera(); if (device != null) { App.CurrentAccount.SelectedCameraId = device.deviceId; accountChanged = true; } } } if (!string.IsNullOrEmpty(App.CurrentAccount.SelectedMicrophoneId)) { List <VATRPDevice> availableMicrophones = GetAvailableMicrophones(); if (IsDeviceAvailable(App.CurrentAccount.SelectedMicrophoneId, availableMicrophones)) { LinphoneService.SetCaptureDevice(App.CurrentAccount.SelectedMicrophoneId); } else { // update the stored setting in the account because the previously selected device is not available VATRPDevice device = GetSelectedMicrophone(); if (device != null) { App.CurrentAccount.SelectedMicrophoneId = device.deviceId; accountChanged = true; } } } if (!string.IsNullOrEmpty(App.CurrentAccount.SelectedSpeakerId)) { List <VATRPDevice> availableSpeakers = GetAvailableSpeakers(); if (IsDeviceAvailable(App.CurrentAccount.SelectedSpeakerId, availableSpeakers)) { LinphoneService.SetSpeakers(App.CurrentAccount.SelectedSpeakerId); } else { // update the stored setting in the account because the previously selected device is not available VATRPDevice device = GetSelectedSpeakers(); if (device != null) { App.CurrentAccount.SelectedSpeakerId = device.deviceId; accountChanged = true; } } } // if there was a change to the account, save it if (accountChanged) { SaveAccountSettings(); } }