protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { string audioFilePath = await ReplaceStringWithSpecialModifiers(this.FilePath, null); if (SoundAction.MixItUpOverlay.Equals(this.OutputDevice)) { IOverlayEndpointService overlay = ChannelSession.Services.Overlay.GetOverlay(ChannelSession.Services.Overlay.DefaultOverlayName); if (overlay != null) { var overlayItem = new OverlaySoundItemModel(audioFilePath, this.VolumeScale); //await overlay.ShowItem(overlayItem, user, arguments, this.extraSpecialIdentifiers, this.platform); } } else { await ChannelSession.Services.AudioService.Play(audioFilePath, this.VolumeScale, this.OutputDevice); } }
public async Task Play(string filePath, int volume, string deviceName) { if (!string.IsNullOrEmpty(filePath)) { if (string.IsNullOrEmpty(deviceName)) { deviceName = ChannelSession.Settings.DefaultAudioOutput; } if (this.MixItUpOverlay.Equals(deviceName)) { IOverlayEndpointService overlay = ChannelSession.Services.Overlay.GetOverlay(ChannelSession.Services.Overlay.DefaultOverlayName); if (overlay != null) { var overlayItem = new OverlaySoundItemModel(filePath, volume); await overlay.ShowItem(overlayItem, new CommandParametersModel()); } } else { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { int deviceNumber = -1; if (!string.IsNullOrEmpty(deviceName)) { deviceNumber = this.GetOutputDeviceID(deviceName); } float floatVolume = MathHelper.Clamp(volume, 0, 100) / 100.0f; using (WaveOutEvent outputDevice = (deviceNumber < 0) ? new WaveOutEvent() : new WaveOutEvent() { DeviceNumber = deviceNumber }) { WaveStream waveStream = null; if (File.Exists(filePath)) { AudioFileReader audioFile = new AudioFileReader(filePath); audioFile.Volume = floatVolume; waveStream = audioFile; } else if (filePath.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) { waveStream = new MediaFoundationReader(filePath); outputDevice.Volume = floatVolume; } if (waveStream != null) { outputDevice.Init(waveStream); outputDevice.Play(); while (outputDevice.PlaybackState == PlaybackState.Playing) { await Task.Delay(500); } waveStream.Dispose(); } } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } } }