Alternative WaveOut class, making use of the Event callback.
More...
|
| WaveOutEvent () |
| Opens a WaveOut device.
|
|
void | Init (IWaveProvider waveProvider) |
| Initializes the WaveOut device with the specified wave provider.
|
|
void | Play () |
| Plays the audio.
|
|
void | Pause () |
| Pauses the audio playback if the current state is playing.
|
|
void | Stop () |
| Stops the playback.
|
|
long | GetPosition () |
| Gets the current position in bytes of the audio playback.
|
|
void | Dispose () |
| Disposes the resources used by the WaveOut device.
|
|
|
void | Dispose (bool disposing) |
| Closes the WaveOut device and disposes of buffers.
|
|
|
int | DesiredLatency [get, set] |
| Gets or sets the desired latency in milliseconds Should be set before a call to Init.
|
|
int | NumberOfBuffers [get, set] |
| Gets or sets the number of buffers used Should be set before a call to Init.
|
|
int | DeviceNumber = -1 [get, set] |
| Gets or sets the device number Should be set before a call to Init This must be between -1 and DeviceCount- 1. -1 means stick to default device even default device is changed.
|
|
WaveFormat | OutputWaveFormat [get] |
| Gets a Wave.WaveFormat instance indicating the format the hardware is using.
|
|
PlaybackState | PlaybackState [get] |
| Playback State.
|
|
float | Volume [get, set] |
| Volume for this device 1.0 is full scale.
|
|
|
void | PlaybackThread () |
| Executes the DoPlayback method in a separate thread and raises the PlaybackStopped event upon completion or in case of an exception.
|
|
void | DoPlayback () |
| Performs the audio playback operation.
|
|
void | Resume () |
| Resumes playback if the current state is paused.
|
|
void | CloseWaveOut () |
| Closes the wave output device and releases associated resources.
|
|
void | DisposeBuffers () |
| Disposes all the buffers and sets them to null.
|
|
| ~WaveOutEvent () |
| Finalizer. Only called when user forgets to call Dispose
|
|
void | RaisePlaybackStoppedEvent (Exception e) |
| Raises the PlaybackStopped event with the specified exception.
|
|
Alternative WaveOut class, making use of the Event callback.
◆ WaveOutEvent()
NAudio.Wave.WaveOutEvent.WaveOutEvent |
( |
| ) |
|
|
inline |
◆ ~WaveOutEvent()
NAudio.Wave.WaveOutEvent.~WaveOutEvent |
( |
| ) |
|
|
inlineprivate |
Finalizer. Only called when user forgets to call Dispose
◆ CloseWaveOut()
void NAudio.Wave.WaveOutEvent.CloseWaveOut |
( |
| ) |
|
|
inlineprivate |
Closes the wave output device and releases associated resources.
This method closes the wave output device and releases any associated resources. If the callbackEvent is not null, it is closed and set to null. The method then locks the waveOutLock and checks if the hWaveOut is not equal to IntPtr.Zero. If it is not, the WaveInterop.waveOutClose method is called to close the wave output device, and hWaveOut is set to IntPtr.Zero.
◆ Dispose() [1/2]
void NAudio.Wave.WaveOutEvent.Dispose |
( |
| ) |
|
|
inline |
Disposes the resources used by the WaveOut device.
- Parameters
-
disposing | A boolean value indicating whether the method is being called from the Dispose method. |
This method stops the WaveOut device and disposes the buffers used by the device. If disposing is true
, it also closes the WaveOut device.
◆ Dispose() [2/2]
void NAudio.Wave.WaveOutEvent.Dispose |
( |
bool | disposing | ) |
|
|
inlineprotected |
Closes the WaveOut device and disposes of buffers.
- Parameters
-
disposing | True if called from Dispose |
◆ DisposeBuffers()
void NAudio.Wave.WaveOutEvent.DisposeBuffers |
( |
| ) |
|
|
inlineprivate |
Disposes all the buffers and sets them to null.
This method disposes all the buffers in the collection and sets the collection to null.
◆ DoPlayback()
void NAudio.Wave.WaveOutEvent.DoPlayback |
( |
| ) |
|
|
inlineprivate |
Performs the audio playback operation.
This method continuously checks the playback state and waits for the callback event with the desired latency. If the playback state is playing and the callback event times out, a warning message is logged. It also requeues any buffers that are returned and checks if all buffers have been queued, indicating the end of playback. If all buffers have been queued, the playback state is set to stopped and the callback event is set.
◆ GetPosition()
long NAudio.Wave.WaveOutEvent.GetPosition |
( |
| ) |
|
Gets the current position in bytes of the audio playback.
- Returns
- The current position in bytes of the audio playback.
Implements NAudio.Wave.IWavePosition.
◆ Init()
Initializes the WaveOut device with the specified wave provider.
- Parameters
-
waveProvider | The wave provider to be initialized. |
- Exceptions
-
InvalidOperationException | Thrown when attempting to re-initialize during playback. |
This method initializes the WaveOut device with the specified wave provider, allocating buffers and setting up the necessary event handling. If the playback state is not stopped, an InvalidOperationException is thrown, indicating that re-initialization during playback is not allowed. If the WaveOut device is already initialized, it is cleaned up and re-initialized with the new wave provider.
Implements NAudio.Wave.IWavePlayer.
◆ Pause()
void NAudio.Wave.WaveOutEvent.Pause |
( |
| ) |
|
|
inline |
Pauses the audio playback if the current state is playing.
- Exceptions
-
MmException | Thrown when an error occurs while pausing the audio playback. |
If the current playback state is playing, this method pauses the audio playback. It sets the playback state to paused to avoid a deadlock problem with some drivers and then pauses the audio output using the WaveInterop.waveOutPause method. If an error occurs during the pause operation, a MmException is thrown with details about the error.
Implements NAudio.Wave.IWavePlayer.
◆ Play()
void NAudio.Wave.WaveOutEvent.Play |
( |
| ) |
|
|
inline |
Plays the audio.
- Exceptions
-
InvalidOperationException | Thrown when buffers or waveStream is null. Must call Init first. |
If the playbackState is stopped, it sets the state to Playing and starts the playback thread using ThreadPool.QueueUserWorkItem. If the playbackState is paused, it resumes the playback and starts the playback thread using ThreadPool.QueueUserWorkItem.
Implements NAudio.Wave.IWavePlayer.
◆ PlaybackThread()
void NAudio.Wave.WaveOutEvent.PlaybackThread |
( |
| ) |
|
|
inlineprivate |
Executes the DoPlayback method in a separate thread and raises the PlaybackStopped event upon completion or in case of an exception.
This method encapsulates the logic for executing the DoPlayback method in a separate thread. Upon completion or in case of an exception, the method updates the playbackState to Stopped and raises the PlaybackStopped event, passing any caught exception as an argument.
◆ RaisePlaybackStoppedEvent()
void NAudio.Wave.WaveOutEvent.RaisePlaybackStoppedEvent |
( |
Exception | e | ) |
|
|
inlineprivate |
Raises the PlaybackStopped event with the specified exception.
- Parameters
-
e | The exception that caused the playback to stop. |
- Exceptions
-
ArgumentNullException | Thrown when the exception is null. |
This method raises the PlaybackStopped event with the specified exception. If a synchronization context is available, the event is raised on the synchronization context; otherwise, it is raised on the current thread.
◆ Resume()
void NAudio.Wave.WaveOutEvent.Resume |
( |
| ) |
|
|
inlineprivate |
Resumes playback if the current state is paused.
- Exceptions
-
MmException | Thrown when an error occurs while trying to resume playback. |
If the current playback state is paused, this method resumes the playback by calling the waveOutRestart function from WaveInterop. The method locks the waveOutLock object to ensure thread safety while calling the waveOutRestart function. If an error occurs during the waveOutRestart call, a MmException is thrown with the corresponding error message. After successful resumption of playback, the playbackState is set to Playing.
◆ Stop()
void NAudio.Wave.WaveOutEvent.Stop |
( |
| ) |
|
|
inline |
Stops the playback.
- Exceptions
-
MmException | Thrown when an error occurs during the waveOutReset operation. |
If the current playback state is not stopped, this method sets the playback state to stopped and resets the waveOut device. This method also signals the callback event to ensure that the thread exits.
Implements NAudio.Wave.IWavePlayer.
◆ buffers
◆ callbackEvent
AutoResetEvent NAudio.Wave.WaveOutEvent.callbackEvent |
|
private |
◆ hWaveOut
IntPtr NAudio.Wave.WaveOutEvent.hWaveOut |
|
private |
◆ playbackState
◆ syncContext
readonly SynchronizationContext NAudio.Wave.WaveOutEvent.syncContext |
|
private |
◆ waveOutLock
readonly object NAudio.Wave.WaveOutEvent.waveOutLock |
|
private |
◆ waveStream
◆ DesiredLatency
int NAudio.Wave.WaveOutEvent.DesiredLatency |
|
getset |
Gets or sets the desired latency in milliseconds Should be set before a call to Init.
◆ DeviceNumber
int NAudio.Wave.WaveOutEvent.DeviceNumber = -1 |
|
getset |
Gets or sets the device number Should be set before a call to Init This must be between -1 and DeviceCount- 1. -1 means stick to default device even default device is changed.
◆ NumberOfBuffers
int NAudio.Wave.WaveOutEvent.NumberOfBuffers |
|
getset |
Gets or sets the number of buffers used Should be set before a call to Init.
◆ OutputWaveFormat
WaveFormat NAudio.Wave.WaveOutEvent.OutputWaveFormat |
|
get |
◆ PlaybackState
◆ Volume
float NAudio.Wave.WaveOutEvent.Volume |
|
getset |
◆ PlaybackStopped
Indicates playback has stopped automatically.
The documentation for this class was generated from the following file:
- /Users/sumansaurabh/Documents/my-startup/xeno-rat/Plugins/LiveMicrophone/lib/NAudio.WinMM/WaveOutEvent.cs