public override bool Init() { try { _ac = new CoreAudioController(); } catch (Exception ex) { Log.Error("Error occured during Init()"); Log.Error(ex.Message); } // Load settings Settings.LoadSettings(); // Button Handler GUIWindowManager.OnNewAction += OnNewAction; Settings.LoadSettings(); if (!string.IsNullOrEmpty(Settings.DefaultPlaybackDevice)) { var devices = GetPlaybackDevices(); Log.Debug("Setting default playback device on startup: " + Settings.DefaultPlaybackDevice); // Find default audio device match to setting CoreAudioDevice playbackDeviceLookup = devices.FirstOrDefault(d => d != null && d.FullName.Equals(Settings.DefaultPlaybackDevice, StringComparison.CurrentCultureIgnoreCase)); if (playbackDeviceLookup != null) { SetPlaybackDevice(playbackDeviceLookup); if (Settings.LAVbitstreamPerDevice) { SetLavBitstreamSettings(playbackDeviceLookup.FullName); } } else { Log.Error("Default playback device not found!"); } } else if (Settings.LAVbitstreamPerDevice) { var devices = GetPlaybackDevices(); // Find default audio device CoreAudioDevice defaultPlaybackDevice = devices.FirstOrDefault(d => d != null && d.IsDefaultDevice); if (defaultPlaybackDevice != null) { SetLavBitstreamSettings(defaultPlaybackDevice.FullName); } else { Log.Error("No playback devices found!"); } } return(true); }
private void DialogContextMenu() { try { // Showing context menu var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); dlg.Reset(); dlg.SetHeading("Audio switcher"); dlg.Add(new GUIListItem("Change playback device")); if (Settings.LAVbitstreamPerDevice || Settings.LAVbitstreamAlwaysShowToggleInContextMenu) { bool bitstreamingIsEnabled = Convert.ToBoolean(Convert.ToInt16(IsLavBitstreamingEnabled())); dlg.Add(bitstreamingIsEnabled ? new GUIListItem("Disable LAV bitstreaming") : new GUIListItem("Enable LAV bitstreaming")); } if (Settings.LAVaudioDelayControlsInContextMenu) { ReadAllLavDelaySettings(); if (!Settings.LAVaudioDelayEnabled) { dlg.Add(new GUIListItem("Enable LAV audio delay")); } else { dlg.Add(new GUIListItem(string.Format("Change LAV audio delay ( {0}ms )", Settings.LAVaudioDelay))); dlg.Add(new GUIListItem("Disable LAV audio delay")); } } dlg.SelectedLabel = 0; dlg.DoModal(GUIWindowManager.ActiveWindow); if (dlg.SelectedLabelText == "Change playback device") { var devices = GetPlaybackDevices(); var dlgSetPlaybackDevice = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); dlgSetPlaybackDevice.Reset(); dlgSetPlaybackDevice.SetHeading("Select playback device"); dlgSetPlaybackDevice.SelectedLabel = 0; var i = 0; if (devices != null) { foreach (var device in devices) { dlgSetPlaybackDevice.Add(device.FullName); if (device.IsDefaultDevice) { dlgSetPlaybackDevice.SelectedLabel = i; } i++; } } else { dlgSetPlaybackDevice.Add("No playback devices found!"); } dlgSetPlaybackDevice.DoModal(GUIWindowManager.ActiveWindow); if (dlgSetPlaybackDevice.SelectedLabel >= 0) { var selectedDevice = dlgSetPlaybackDevice.SelectedLabelText; if (selectedDevice != "No playback devices found!" && !string.IsNullOrEmpty(selectedDevice)) { var device = devices.ElementAt(dlgSetPlaybackDevice.SelectedLabel); SetPlaybackDevice(device); } } } if (dlg.SelectedLabelText == "Enable LAV bitstreaming") { ToggleLAVBitstreaming(true, "", true); } if (dlg.SelectedLabelText == "Disable LAV bitstreaming") { ToggleLAVBitstreaming(false, "", true); } if (dlg.SelectedLabelText.StartsWith("Disable LAV audio delay")) { SetLavAudioDelay(false, ""); RestartVideoPlayback(false, ""); } if (dlg.SelectedLabelText == "Enable LAV audio delay" || dlg.SelectedLabelText.StartsWith("Change LAV audio delay")) { SelectLavAudioDelay(); } // Save settings Settings.SaveSettings(); } catch (Exception ex) { Log.Error("Error occured during DialogContextMenu()"); Log.Error(ex.Message); } }