A basic audio player for .NET. It's a simple wrapper for NAudio that allows you to set an audio file together with an ID string. This file can then be played, paused, stopped. TrackFinished and TrackStopped events will be fired when the respective events happen and the ID string will be passed in the EventArgs. A PositionChanged event will be fired every second when the file is playing, the EventArgs contain a TrackPosition instance that has info about the current position in the track.
Wave, Vorbis, MP3 and AAC audio formats are supported, but this may be extended when I need other ones or there is a demand for this.
Currently it's not supported to seek through the playing track, this feature will be implemented in the future. In the future it will be possible to set the interval at which the PositionChanged event is fired.
This project is available as a NuGet package here: https://www.nuget.org/packages/Stannieman.AudioPlayer/
Enum representing various audio types.
Indicates that a track finished playing.
Indicates that a track stopped playing but was not finished.
Indicates that the position in a track has changed.
Default constructor.
Sets a file to play and sets the ID of the track for that file name.
Name | Description |
---|---|
fullFileName: | Full path of the file to play. |
trackId: | ID of the track. |
Returns: Task instance. | |
[[T:Stannieman.AudioPlayer.AudioPlayerException | T:Stannieman.AudioPlayer.AudioPlayerException]]: If something goes wrong while setting the file. |
Starts playback of the set file.
Returns: Task instance.
[[T:Stannieman.AudioPlayer.AudioPlayerException|T:Stannieman.AudioPlayer.AudioPlayerException]]: If something goes wrong while starting the playback of the set file.
Pauses playback of the set file.
Returns: Task instance.
[[T:Stannieman.AudioPlayer.AudioPlayerException|T:Stannieman.AudioPlayer.AudioPlayerException]]: If something goes wrong while pausing the playback of the set file.
Stops playback of the set file.
Returns: Task instance.
[[T:Stannieman.AudioPlayer.AudioPlayerException|T:Stannieman.AudioPlayer.AudioPlayerException]]: If something goes wrong while stopping the playback of the set file.
Returns the current position in the track.
Returns: Current position in the track.
Callback for the timer to report the position in the track.
Name | Description |
---|---|
state: | State. |
M:Stannieman.AudioPlayer.AudioPlayer.OnPlaybackStoppedAsync(System.Object,NAudio.Wave.StoppedEventArgs)
Handler for if playback of a file stopped.
Name | Description |
---|---|
sender: | Sender. |
e: | StoppedEventArgs. |
Returns: Task instance. |
Returns the audio format for a given file name. The returned format is based on the file's extension.
Name | Description |
---|---|
fileName: | File name to get audio format for. |
Returns: The audio format of the file. |
Disposes the player.
EventArgs for events to report a track has finished playing.
ID of the track that finished playing.
Constructor accepting a track ID of a track that finished playing.
Name | Description |
---|---|
trackId: | ID of the track. |
EventArgs for events to report the current position in a track.
ID of the track of which the position changed.
The position in the track.
M:Stannieman.AudioPlayer.PositionChangedEventArgs.#ctor(System.String,Stannieman.AudioPlayer.TrackPosition)
Constructor accepting a track ID and a trackposition struct representing the position in the track.
Name | Description |
---|---|
trackId: | ID of the track. |
trackPosition: | A TrackPosition instance. |
Exception regarding an audio player.
Default constructor.
Constructor taking a message that describes the error.
Name | Description |
---|---|
message: | Message. |
Constructor taking a message that describes the error and an inner exception.
Name | Description |
---|---|
message: | Message. |
innerException: | Inner exception. |
Indicates that a track finished playing.
Indicates that a track stopped playing but was not finished.
Indicates that the position in a track has changed.
Sets a file to play and sets the ID of the track for that file name.
Name | Description |
---|---|
fullFileName: | Full path of the file to play. |
trackId: | ID of the track. |
Returns: Task instance. |
Starts playback of the set file.
Returns: Task instance.
Pauses playback of the set file.
Returns: Task instance.
Stops playback of the set file.
Returns: Task instance.
Returns the current position in the track.
Returns: Current position in the track.
Struct representing a track's duration and a position in the track.
Duration of the track.
Position in the track.
Constructor taking time spans that represent the duration of a track and a position in the track.
Name | Description |
---|---|
duration: | Duration of a track. |
currentTime: | Position in a track. |
Equals implementation to check if a given TrackPosition instance equals this one.
Name | Description |
---|---|
trackPosition: | Trackposition to check equality of. |
Returns: Whether the given instance is equal to this one. |