使用C#播放MP3文件#
答
我已经写了叫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();
}
答
我不明白你为什么要避开第三方库。如果你使用c#编写代码,你可能正在开发windows,通常有winmm.dll。所以你可以导入并使用mciSendString
like in this example。
但是,如果您将MP3数据转换为原始数据,则可以使用.NET SoundPlayer类进行播放。
的([使用C#中的WinForms播放声音]可能重复http://stackoverflow.com/questions/1304223/playing- winform-using-c-sharp) – Alejandro 2014-06-14 15:34:10