Class WaveOutWindow
Plays audio using the winmm waveOut API with CALLBACK_WINDOW, so that buffer-done
notifications are delivered on the UI thread's message pump. Useful when you want
PlaybackStopped and internal buffer recycling to happen on the UI thread
without any manual marshaling. For background-thread playback use
WaveOut in the NAudio.WinMM package instead.
public class WaveOutWindow : IWavePlayer, IDisposable, IWavePosition, IWaveLatency
- Inheritance
-
WaveOutWindow
- Implements
- Inherited Members
Constructors
WaveOutWindow()
Creates a WaveOutWindow that owns a hidden callback window. Must be constructed on a thread with a running Windows Forms message loop.
public WaveOutWindow()
WaveOutWindow(nint)
Creates a WaveOutWindow that subclasses an existing window so its HWND receives waveOut callbacks. The handle must belong to a window whose message loop is running on the thread that constructs this instance.
public WaveOutWindow(nint windowHandle)
Parameters
windowHandlenint
Properties
AverageLatency
The steady-state latency from a sample being queued for output to it being emitted by the audio hardware, assuming uninterrupted playback. This is a property of the buffer configuration and the driver, not of the current playback state.
public TimeSpan AverageLatency { get; }
Property Value
Remarks
Mirrors the calculation in WaveOut: in steady state every queued buffer plus half of the one currently playing sits between the application and the speaker.
CurrentLatency
The time that has elapsed since the sample currently emerging from the hardware was queued for output. In steady state this is approximately equal to AverageLatency; it differs during start-up, after an underrun, or when the host is filling buffers irregularly. Implementations that cannot meaningfully distinguish from the average are permitted to return AverageLatency.
public TimeSpan CurrentLatency { get; }
Property Value
DesiredLatency
Desired latency in milliseconds. Must be set before Init(IWaveProvider).
public int DesiredLatency { get; set; }
Property Value
DeviceCount
Returns the number of waveOut devices available on the system.
public static int DeviceCount { get; }
Property Value
DeviceNumber
Device number. -1 (default) tracks the current default device.
public int DeviceNumber { get; set; }
Property Value
NumberOfBuffers
Number of buffers used. Must be set before Init(IWaveProvider).
public int NumberOfBuffers { get; set; }
Property Value
OutputWaveFormat
The format the hardware is using.
public WaveFormat OutputWaveFormat { get; }
Property Value
PlaybackState
Playback state.
public PlaybackState PlaybackState { get; }
Property Value
Volume
Volume for this device. 1.0 is full scale.
public float Volume { get; set; }
Property Value
Methods
Dispose()
Closes this device.
public void Dispose()
Dispose(bool)
Closes the device and disposes of buffers.
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
~WaveOutWindow()
Finaliser, called only if the user forgets to call Dispose().
protected ~WaveOutWindow()
GetCapabilities(int)
Retrieves the capabilities of a waveOut device.
public static WaveOutCapabilities GetCapabilities(int devNumber)
Parameters
devNumberint
Returns
GetPosition()
Current byte position as reported by waveOutGetPosition.
public long GetPosition()
Returns
Init(IWaveProvider)
Initialises the device with the provider to be played.
public void Init(IWaveProvider waveProvider)
Parameters
waveProviderIWaveProvider
Pause()
Pause playback.
public void Pause()
Play()
Start playing.
public void Play()
Resume()
Resume playback from a paused state.
public void Resume()
Stop()
Stop and reset the device. PlaybackStopped is raised from the buffer-done callback once all outstanding buffers have been returned.
public void Stop()
Events
PlaybackStopped
Indicates playback has stopped automatically (end of stream or an error).
public event EventHandler<StoppedEventArgs> PlaybackStopped