/// <summary> /// Initializes a new instance of the <see cref="AudioPlayer"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="configuration">The component configuration.</param> public AudioPlayer(Pipeline pipeline, AudioPlayerConfiguration configuration) : base(pipeline) { this.pipeline = pipeline; this.configuration = configuration; this.currentInputFormat = configuration.InputFormat; this.AudioLevelInput = pipeline.CreateReceiver <double>(this, this.SetAudioLevel, nameof(this.AudioLevelInput)); this.AudioLevel = pipeline.CreateEmitter <double>(this, nameof(this.AudioLevel)); this.wasapiRender = new WasapiRender(); this.wasapiRender.Initialize(configuration.DeviceName); if (configuration.AudioLevel >= 0) { this.wasapiRender.AudioLevel = configuration.AudioLevel; } }
/// <summary> /// Initializes a new instance of the <see cref="AudioPlayer"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="configuration">The component configuration.</param> public AudioPlayer(Pipeline pipeline, AudioPlayerConfiguration configuration) : base(pipeline) { pipeline.RegisterPipelineStartHandler(this, this.OnPipelineStart); pipeline.RegisterPipelineStopHandler(this, this.OnPipelineStop); this.pipeline = pipeline; this.configuration = configuration; this.currentInputFormat = configuration.InputFormat; this.AudioLevelInput = pipeline.CreateReceiver <double>(this, this.SetAudioLevel, nameof(this.AudioLevelInput)); this.AudioLevel = pipeline.CreateEmitter <double>(this, nameof(this.AudioLevel)); this.wasapiRender = new WasapiRender(); this.wasapiRender.Initialize(configuration.DeviceName); this.pipeline.PipelineCompletionEvent += this.OnPipelineCompletionEvent; if (configuration.AudioLevel >= 0) { this.wasapiRender.AudioLevel = configuration.AudioLevel; } }
/// <summary> /// Gets a list of available audio render devices. /// </summary> /// <returns> /// An array of available render device names. /// </returns> public static string[] GetAvailableDevices() { return(WasapiRender.GetAvailableRenderDevices()); }
/// <summary> /// Disposes the <see cref="AudioPlayer"/> object. /// </summary> public void Dispose() { this.StopRendering(); this.wasapiRender.Dispose(); this.wasapiRender = null; }
/// <summary> /// Disposes the <see cref="AudioPlayer"/> object. /// </summary> public void Dispose() { this.OnPipelineStop(); this.wasapiRender.Dispose(); this.wasapiRender = null; }