是否有一些免费的商用音频库(如NAudio)可以播放mp3 (但不能播放NAudio!)非常感谢!:)
发布于 2011-07-08 05:08:25
您可以使用内置的WMPLib -请参阅Creating the Windows Media Player Control Programmatically上的这篇MSDN文章。
在最基本的级别上,您需要这样的代码:
private void PlayFile(String url)
{
Player = new WMPLib.WindowsMediaPlayer();
Player.URL = url;
Player.controls.play();
}但是,您还会获得一些事件来通知您播放状态已更改,因此您可以开始播放新曲目,或关闭窗体(例如):
Player.PlayStateChange +=
new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange)
private void Player_PlayStateChange(int NewState)
{
if ((WMPLib.WMPPlayState)NewState == WMPLib.WMPPlayState.wmppsStopped)
{
this.Close();
}
}这确实意味着你的应用程序绑定到Windows上--所以你不能使用Mono。
发布于 2011-07-08 05:12:46
您可以尝试使用DirectSound。在VS2008或更高版本中,DirectSound的条目将从“添加引用”对话框中删除(我认为),但您仍然可以在GAC中浏览合适的DLL。查找最新版本。这很简单,就像这样:
Device dev = new Device();
dev.SetCooperativeLevel(this.Handle, CooperativeLevel.Priority); // this refers to the form to which DirectSound is tied
SecondaryBuffer sound = new SecondaryBuffer("path\\to\\file", dev);
sound.Volume = /* volume */;
sound.Play(0, BufferPlayFlags.Default);https://stackoverflow.com/questions/6617168
复制相似问题