Browse Source

Added another tutorial

pull/260/head
Mark Heath 8 years ago
parent
commit
9e4eef6dc2
  1. 4
      Docs/GettingStarted.md
  2. 22
      Docs/PlayAudioFileConsoleApp.md
  3. 1
      NAudio.sln
  4. 3
      README.md

4
Docs/GettingStarted.md

@ -7,7 +7,7 @@ The most common namespaces you'll want to reference are:
- `NAudio.Wave`
- `NAudio.Wave.SampleProviders`
## Play Audio from a WinForms application
## Play an Audio File from a WinForms application
In this demo, we'll see how to play an audio file from a WinForms application. This technique will also work
@ -103,4 +103,4 @@ private void OnPlaybackStopped(object sender, StoppedEventArgs args)
}
```
And that's it. Congratulations, you've played your first audio file from a
And that's it. Congratulations, you've played your first audio file with NAudio.

22
Docs/PlayAudioFileConsoleApp.md

@ -0,0 +1,22 @@
## Play an Audio File from a Console application
To play a file from a console application, we will use `AudioFileReader` as a simple way of opening our audio file, and `WaveOutEvent` as the output device.
We simply need to pass the `audioFile` into the `outputDevice` with the `Init` method, and then call `Play`.
Since `Play` only means "start playing" and isn't blocking, we can wait in a loop until playback finishes.
Afterwards, we need to `Dispose` our `audioFile` and `outputDevice`, which in this example we do by virtue of putting them inside `using` blocks.
```c#
using(var audioFile = new AudioFileReader(audioFile))
using(var outputDevice = new WaveOutEvent())
{
outputDevice.Init(audioFile);
outputDevice.Play();
while (outputDevice.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(1000);
}
}
```

1
NAudio.sln

@ -33,6 +33,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{BA7F6DBB-9FC4-49E6-92E4-621EFE4BBBBC}"
ProjectSection(SolutionItems) = preProject
Docs\GettingStarted.md = Docs\GettingStarted.md
Docs\PlayAudioFileConsoleApp.md = Docs\PlayAudioFileConsoleApp.md
EndProjectSection
EndProject
Global

3
README.md

@ -5,7 +5,8 @@ NAudio is an open source .NET audio library written by [Mark Heath](https://mark
We're currently in the process of migrating documentation from [CodePlex](http://naudio.codeplex.com).
- [Getting Started](Docs/GettingStarted.md)
- [Playing an Audio File from a WinForms application](Docs/GettingStarted.md)
- [Playing an Audio File from a Console application](Docs/PlayAudioConsoleApp.md)
Additional sources of documentation for NAudio are:
- [Original Documentation on CodePlex](http://naudio.codeplex.com/documentation)

Loading…
Cancel
Save