public IHttpContext GetSound(IHttpContext context) { if (Authentication.Enabled) { HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity; if (!Authentication.VerifyAuthentication(identity)) { context.Response.SendResponse(JsonConvert.SerializeObject(Authentication.FailedAuthentication)); return(context); } } SoundDevices sd = new SoundDevices(); CoreAudioController controller = new CoreAudioController(); var devices = controller.GetPlaybackDevices(); foreach (CoreAudioDevice device in devices) { try { sd.SoundDevice.Add(new SoundDeviceInfo { ID = device.RealId, FriendlyName = device.FullName, State = device.State.ToString() }); sd.Response = new ResponseMessage { Message = "Successfully got active audio device(s).", Successful = true }; } catch (Exception) { sd.Response = new ResponseMessage { Message = "Failed to get audio device(s).", Successful = false }; controller.Dispose(); } } controller.Dispose(); context.Response.ContentEncoding = Encoding.Default; context.Response.SendResponse(JsonConvert.SerializeObject(sd)); return(context); }
protected override void OnStop() { SetServiceState(ServiceState.SERVICE_STOP_PENDING, 100000); CommandStack.Add(new PowerChangeCommandItem(false)); PerformCommandStack().Wait(); _logger.Info("Service Stopped."); _controller.Dispose(); SetServiceState(ServiceState.SERVICE_STOPPED); }
static public List <string> GetDevices() { var cac = new CoreAudioController(); List <string> tmp = new List <string>(); foreach (CoreAudioDevice de in cac.GetPlaybackDevices()) { tmp.Add(de.FullName); } cac.Dispose(); return(tmp); }
public IHttpContext SetSound(IHttpContext context) { if (Authentication.Enabled) { HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity; if (!Authentication.VerifyAuthentication(identity)) { context.Response.SendResponse(JsonConvert.SerializeObject(Authentication.FailedAuthentication)); return(context); } } ResponseMessage Response = new ResponseMessage(); Response.Message = "Please input correct id or name. Get id by using /getid"; Response.Successful = false; var enc = Encoding.GetEncoding(context.Request.ContentEncoding.CodePage); var id = Encoding.UTF8.GetString(enc.GetBytes(context.Request.QueryString["id"])) ?? JsonConvert.SerializeObject(Response); CoreAudioController controller = new CoreAudioController(); var devices = controller.GetPlaybackDevices(); foreach (CoreAudioDevice device in devices) { if (device.RealId == id) { controller.SetDefaultDevice(device); Response.Message = $"Switched to audio device: {device.FullName}"; Response.Successful = true; } if (device.FullName == id && device.State == AudioSwitcher.AudioApi.DeviceState.Active) { try { controller.SetDefaultDevice(device); Response.Message = $"Switched to audio device: {device.FullName}"; Response.Successful = true; } catch (Exception) { } } } controller.Dispose(); context.Response.ContentEncoding = Encoding.Default; context.Response.SendResponse(JsonConvert.SerializeObject(Response)); return(context); }
internal void ArmedMode() { while (_armed) { if (_armed && _isRunningOnBattery) { CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; defaultPlaybackDevice.Volume = 100; Stream alarmStream = Properties.Resources.Alarm; System.Media.SoundPlayer alarmRecording = new System.Media.SoundPlayer(alarmStream); Dispatcher.Invoke(() => { if (_armed) { DisplayArmStatus.Text = "Alarm Triggered!"; } }); alarmRecording.Play(); for (int i = 0; i < 880; i++) { System.Threading.Thread.Sleep(100); if (_armed) { continue; } else { break; } } alarmRecording.Stop(); alarmRecording.Dispose(); alarmStream.Dispose(); defaultPlaybackDevice.Dispose(); } System.Threading.Thread.Sleep(500); } }
public void Dispose() { _controller.Dispose(); }