使用C#播放MP3文件

idi*_*ish 2 c# audio

我正在寻找一种播放MP3文件的方法,没有任何第三方播放它(媒体播放器等)有没有办法做到这一点?谢谢.

Mar*_*ath 8

我写了一个名为NAudio的开源库,它可以做到这一点:

private IWavePlayer waveOut;
private Mp3FileReader mp3FileReader;

private void PlayMp3()
{
    this.waveOut = new WaveOut(); // or new WaveOutEvent() if you are not using WinForms/WPF
    this.mp3FileReader = new Mp3FileReader("myfile.mp3");
    this.waveOut.Init(mp3FileReader);
    this.waveOut.Play();
    this.waveOut.PlaybackStopped += OnPlaybackStopped;
}

private void OnPlaybackStopped(object sender, EventArgs e)
{
    this.waveOut.Dispose();
    this.mp3FileReader.Dispose();
}
Run Code Online (Sandbox Code Playgroud)