public void Attach(IAudioPlaybackProvider audioPlayback, IEnumerable <AudioSource> sources, AudioEnginePlaybackOptions options) { if (audioPlayback == null) { throw new ArgumentNullException("audioPlayback"); } if (sources == null) { throw new ArgumentNullException("sources"); } if (options == null) { throw new ArgumentNullException("options"); } lock (playbacks) { if (!this.playbackProviders.Contains(audioPlayback)) { audioPlayback.SourceFinished += OnSourceFinished; this.playbackProviders.Add(audioPlayback); } foreach (var s in sources.Where(s => !playbacks.ContainsKey(s) && s.OwnerId != Context.CurrentUser.UserId)) { audioPlayback.SetGain(s, options.Gain); playbacks[s] = new AudioPlaybackEntity(audioPlayback, s, options); if (mutedPlayers.Contains(audioPlayback)) { playbacks[s].Muted = true; } } } }
public bool Detach(IAudioPlaybackProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } bool removed = false; lock (playbacks) { this.playbackProviders.Remove(provider); provider.SourceFinished -= OnSourceFinished; foreach (var entity in playbacks.Values.Where(e => e.AudioPlayback == provider).ToList()) { entity.AudioPlayback.FreeSource(entity.Source); playbacks.Remove(entity.Source); removed = true; } mutedPlayers.Remove(provider); } return(removed); }
private void MuteCore(IAudioPlaybackProvider audioPlayback, bool mute) { if (audioPlayback == null) { throw new ArgumentNullException("audioPlayback"); } lock (playbacks) { if (mute) { mutedPlayers.Add(audioPlayback); } else { mutedPlayers.Remove(audioPlayback); } var ps = playbacks.Values.Where(e => e.AudioPlayback == audioPlayback); foreach (var e in ps) { e.Muted = mute; } } }
public void Attach(IAudioPlaybackProvider audioPlayback, AudioSource source, AudioEnginePlaybackOptions options) { if (audioPlayback == null) { throw new ArgumentNullException("audioPlayback"); } if (source == null) { throw new ArgumentNullException("source"); } if (options == null) { throw new ArgumentNullException("options"); } lock (playbacks) { if (!this.playbackProviders.Contains(audioPlayback)) { audioPlayback.SourceFinished += OnSourceFinished; this.playbackProviders.Add(audioPlayback); } audioPlayback.SetGain(source, options.Gain); playbacks[source] = new AudioPlaybackEntity(audioPlayback, source, options); if (mutedPlayers.Contains(audioPlayback)) { playbacks[source].Muted = true; } } }
public AudioPlaybackSettingsViewModel() { PlaybackProviders = Modules.Playback; IAudioPlaybackProvider savedPlaybackProvider = Modules.Playback.FirstOrDefault(p => p.GetType().GetSimpleName() == Settings.PlaybackProvider); if (savedPlaybackProvider == null) { CurrentPlaybackProvider = Modules.Playback.FirstOrDefault(); } else { CurrentPlaybackProvider = savedPlaybackProvider; if (Settings.PlaybackDevice != null) { var setDevice = PlaybackDevices.FirstOrDefault(d => d.Device.Name == Settings.PlaybackDevice); if (setDevice != null) { CurrentPlaybackDevice = setDevice; } } } Volume = Settings.GlobalVolume * 100; }
/// <summary> /// Opens the provider with <paramref name="device"/>. /// </summary> /// <param name="device">The device to play audio on.</param> /// <exception cref="ArgumentNullException"><paramref name="device"/> is <c>null</c>.</exception> public static void Open(this IAudioPlaybackProvider self, IAudioDevice device) { if (self == null) { throw new ArgumentNullException("self"); } if (device == null) { throw new ArgumentNullException("device"); } self.Device = device; self.Open(); }
private void SetupPlayback() { DisablePlayback(); if (!this.gablarski.IsConnected) { return; } try { if (Settings.PlaybackProvider == null) { throw new Exception("Playback provider is not set"); } this.audioPlayback = (IAudioPlaybackProvider)Activator.CreateInstance(Type.GetType(Settings.PlaybackProvider)); if (Settings.PlaybackDevice.IsNullOrWhitespace() || Settings.PlaybackDevice == "Default") { this.audioPlayback.Device = this.audioPlayback.DefaultDevice; } else { this.audioPlayback.Device = this.audioPlayback.GetDevices().FirstOrDefault(d => d.Name == Settings.PlaybackDevice) ?? this.audioPlayback.DefaultDevice; } this.audioPlayback.Open(); this.audioPlayback.Gain = Settings.GlobalVolume; this.gablarski.Sources.Where(s => s.OwnerId != gablarski.CurrentUser.UserId) .ForEach(AttachSource); BeginInvoke((Action)(() => { if (btnMute.Checked && !this.playbackDisabled) { return; } btnMute.Image = Resources.SoundMuteImage; btnMute.Checked = false; btnMute.Enabled = true; btnMute.ToolTipText = "Mute Sound"; if (this.playbackDisabled) { btnMuteMic.Checked = false; } this.playbackDisabled = false; })); } catch (Exception ex) { Program.Raygun.Send(ex, new[] { "playback-init" }, Settings.CurrentSettings); if (this.audioPlayback != null) { this.audioPlayback.Dispose(); } this.audioPlayback = null; BeginInvoke((Action)(() => { this.playbackDisabled = true; btnMute.Image = Resources.SoundMuteImage.ToErrorIcon(); btnMute.Checked = true; btnMute.Enabled = false; btnMute.ToolTipText = "Playback Initialization error: " + ex.Message; })); } if (this.audioPlayback != null && Settings.EnableNotifications) { SetupNotifications(); this.notifications.Notify(NotificationType.Connected, "Connected"); } }
private void MuteCore(IAudioPlaybackProvider audioPlayback, bool mute) { if (audioPlayback == null) throw new ArgumentNullException ("audioPlayback"); lock (playbacks) { if (mute) mutedPlayers.Add (audioPlayback); else mutedPlayers.Remove (audioPlayback); var ps = playbacks.Values.Where (e => e.AudioPlayback == audioPlayback); foreach (var e in ps) e.Muted = mute; } }
public void Unmute(IAudioPlaybackProvider audioPlayback) { MuteCore (audioPlayback, false); }
public void Mute(IAudioPlaybackProvider audioPlayback) { MuteCore (audioPlayback, true); }
public bool Detach(IAudioPlaybackProvider provider) { if (provider == null) throw new ArgumentNullException("provider"); bool removed = false; lock (playbacks) { this.playbackProviders.Remove (provider); provider.SourceFinished -= OnSourceFinished; foreach (var entity in playbacks.Values.Where (e => e.AudioPlayback == provider).ToList()) { entity.AudioPlayback.FreeSource (entity.Source); playbacks.Remove (entity.Source); removed = true; } mutedPlayers.Remove (provider); } return removed; }
public void Attach(IAudioPlaybackProvider audioPlayback, AudioSource source, AudioEnginePlaybackOptions options) { if (audioPlayback == null) throw new ArgumentNullException ("audioPlayback"); if (source == null) throw new ArgumentNullException ("source"); if (options == null) throw new ArgumentNullException ("options"); lock (playbacks) { if (!this.playbackProviders.Contains (audioPlayback)) { audioPlayback.SourceFinished += OnSourceFinished; this.playbackProviders.Add (audioPlayback); } audioPlayback.SetGain (source, options.Gain); playbacks[source] = new AudioPlaybackEntity (audioPlayback, source, options); if (mutedPlayers.Contains (audioPlayback)) playbacks[source].Muted = true; } }
public AudioPlaybackEntity(IAudioPlaybackProvider audioPlayback, AudioSource source, AudioEnginePlaybackOptions options) { this.audioPlayback = audioPlayback; this.source = source; this.options = options; }
public void Unmute(IAudioPlaybackProvider audioPlayback) { MuteCore(audioPlayback, false); }
public void Mute(IAudioPlaybackProvider audioPlayback) { MuteCore(audioPlayback, true); }
private void SetupPlayback () { DisablePlayback(); if (!this.gablarski.IsConnected) return; try { if (Settings.PlaybackProvider == null) throw new Exception ("Playback provider is not set"); this.audioPlayback = (IAudioPlaybackProvider) Activator.CreateInstance (Type.GetType (Settings.PlaybackProvider)); if (Settings.PlaybackDevice.IsNullOrWhitespace() || Settings.PlaybackDevice == "Default") this.audioPlayback.Device = this.audioPlayback.DefaultDevice; else { this.audioPlayback.Device = this.audioPlayback.GetDevices().FirstOrDefault (d => d.Name == Settings.PlaybackDevice) ?? this.audioPlayback.DefaultDevice; } this.audioPlayback.Open(); this.audioPlayback.Gain = Settings.GlobalVolume; this.gablarski.Sources.Where (s => s.OwnerId != gablarski.CurrentUser.UserId) .ForEach (AttachSource); BeginInvoke ((Action)(() => { if (btnMute.Checked && !this.playbackDisabled) return; btnMute.Image = Resources.SoundMuteImage; btnMute.Checked = false; btnMute.Enabled = true; btnMute.ToolTipText = "Mute Sound"; if (this.playbackDisabled) btnMuteMic.Checked = false; this.playbackDisabled = false; })); } catch (Exception ex) { Program.Raygun.Send (ex, new[] { "playback-init" }, Settings.CurrentSettings); if (this.audioPlayback != null) this.audioPlayback.Dispose(); this.audioPlayback = null; BeginInvoke ((Action) (() => { this.playbackDisabled = true; btnMute.Image = Resources.SoundMuteImage.ToErrorIcon(); btnMute.Checked = true; btnMute.Enabled = false; btnMute.ToolTipText = "Playback Initialization error: " + ex.Message; })); } if (this.audioPlayback != null && Settings.EnableNotifications) { SetupNotifications(); this.notifications.Notify (NotificationType.Connected, "Connected"); } }
public void Attach(IAudioPlaybackProvider audioPlayback, IEnumerable<AudioSource> sources, AudioEnginePlaybackOptions options) { if (audioPlayback == null) throw new ArgumentNullException ("audioPlayback"); if (sources == null) throw new ArgumentNullException ("sources"); if (options == null) throw new ArgumentNullException ("options"); lock (playbacks) { if (!this.playbackProviders.Contains (audioPlayback)) { audioPlayback.SourceFinished += OnSourceFinished; this.playbackProviders.Add (audioPlayback); } foreach (var s in sources.Where (s => !playbacks.ContainsKey (s) && s.OwnerId != Context.CurrentUser.UserId)) { audioPlayback.SetGain (s, options.Gain); playbacks[s] = new AudioPlaybackEntity (audioPlayback, s, options); if (mutedPlayers.Contains (audioPlayback)) playbacks[s].Muted = true; } } }