1 Star 2 Fork 0

UnitySir/NAudio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PlayAudioFileConsoleApp.md 849 Bytes
一键复制 编辑 原始数据 按行查看 历史
Mark Heath 提交于 8年前 . Added another tutorial

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.

using(var audioFile = new AudioFileReader(audioFile))
using(var outputDevice = new WaveOutEvent())
{
    outputDevice.Init(audioFile);
    outputDevice.Play();
    while (outputDevice.PlaybackState == PlaybackState.Playing)
    {
        Thread.Sleep(1000);
    }
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/unitysir_admin/NAudio.git
git@gitee.com:unitysir_admin/NAudio.git
unitysir_admin
NAudio
NAudio
master

搜索帮助